【问题标题】:Is it possible to create a WS-client from WSDL file using Spring-WS? (It seems not)是否可以使用 Spring-WS 从 WSDL 文件创建 WS 客户端? (好像没有)
【发布时间】:2012-12-10 15:31:19
【问题描述】:

我想知道是否可以使用 Spring Web Services 从 WSDL 文件创建 Web Services 客户端

我的意思是从 WSDL 开始,我暂时没有任何 XSD。

但我已经阅读了 Josh Long 的“Spring Recipes A Problem-Solution Approach”、Hamidreza Sattari 的“Spring Web Services 2 Cookbook”以及教程本身 (6. Using Spring Web Services on the Client),但没有提及此功能。

我还阅读了其他帖子,例如 Webservice-Client: Common approach with Spring WS, JAXB and just one WSDL file?Spring-ws client from WSDL(在 stackoverflow 上),但没有任何进一步的结果。

我什至在 Spring 论坛上问过这个问题,但阅读超过 60 次后没有回复:Is it possible to create a WS-client from WSDL file using SWS? (It seems not)

也许这是不可能的。

谢谢。

【问题讨论】:

  • 你说“创建一个 WS 客户端”是什么意思?因为您可以使用 WebServiceTemplate 类在 SOAP 消息中包装您想要的任何内容。我怀疑您真的在考虑创建客户端可以使用的 POJO 类。如果您在 WSDL 中有 type 部分,那么您可以通过 XJC 编译器运行该 WSDL 并获取您的类。
  • ¿没有进一步的结果?你在这个过程中发现了哪些错误?你试过什么?请显示一些代码。
  • 谢谢@kdgregory,我真正的意思是我想Send and receive POJOs: marshalling and unmarshalling,所以我需要XJC。也感谢 Alfabravo 对我的问题表现出兴趣。我唯一的问题是像 kdgregory 所说的那样生成 POJO。我可以send a WebServiceMessage with WebServiceTemplate,但静态字符串消息(用于使用 StringReader 创建 StreamSource)不是我想要的。

标签: java spring wsdl spring-ws


【解决方案1】:

你可以这样做:

  1. 使用 JDK 发行版附带的 xjc 工具生成您的 java 类型 - xjc -wsdl file.wsdl

  2. 然后使用生成的java类型,使用WebserviceTemplate,描述here创建客户端。

【讨论】:

  • 我不知道 -wsdl 选项(实际上我习惯使用 maven,所以我通常使用一些插件作为 jaxb2-maven-plugin 来调用 XJC,没有进一步深入细节) 感谢@Biju Kunjummen 向我展示了正确的选项。明天我去试试。
  • 你仍然可以使用maven插件来生成基于wsdl的类,查看this option
  • 出于好奇-您知道如何从 Eclipse 生成 xjc -wsdl 命令吗?我创建了一个 Eclipse 项目,右键单击 wsdl 文件,并查看了“Web 服务”菜单下的不同选项,但似乎都不对。
猜你喜欢
  • 2013-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
相关资源
最近更新 更多