用 Java 编写 Soap 请求
我有一个 wsdl 文件和一个详细文档,其中包含来自 Web 服务提供商的每个请求和响应中的所有元素。我的工作是编写大约 40 个请求并解析相应的响应。
更具体地说,我们的平台提交请求并从服务获取响应,因此对于我来说,作为应用程序开发人员,我只需要编写肥皂请求并将它们作为字符串传递给平台。我还从平台得到字符串响应。
我尝试过 StringBuilder,但它看起来很原始。它必须是一个更好的方法来做到这一点。
我可以将所有请求放入 xml 文档中并以某种方式从中生成请求吗?
或者更好的是,是否可以从 wsdl 文件生成请求?
谢谢,
莎拉
I have a wsdl file and a detailed document about all the elements in every request and response from a web-service provider. My job is to compose around 40 requests and parse corresponding responses.
More specifically, our platform submits the requests and gets responses from the service, so for me, as an application developer, I only need to compose soap requests and pass them as String to the platform. I also get response as String from the platform.
I tried StringBuilder, but it looks pretty primitive. It has to be a better way to do it.
Can I put all the requests in an xml document and somehow generate requests from it?
Or even better, is it possible to generate requests from the wsdl file?
Thanks,
Sarah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下 wsdl2java 实用程序(有多个版本,一个与 Axis2 一起打包,另一个来自 IBM,等等)。这些可以从您的 WSDL 生成客户端存根,并且应该为您节省大量的工作。
编辑:刚刚意识到这可能需要一些额外的工作,因为您说您的平台提交了请求。生成的代码应该尝试将字符串提交到服务(如果您的 WSDL 指定了该字符串),也许您可以修改代码以将字符串传递到您的平台?
JAX-WS 的 wsimport
带有 XFire 的客户端存根
Axis2 的 wsdl2java
IBM 的 wsdl2java
Have a look at the wsdl2java utilities (there are several versions, one packaged with Axis2, another from IBM, etc.). These can generate client stubs from your WSDL, and should save you a considerable amount of work.
EDIT: Just realized that this may require some additional work since you say your platform submits the requests. The generated code should be attempting to submit strings to the service if that is what's specified by your WSDL, perhaps you can modify the code to pass the strings to your platform?
JAX-WS's wsimport
Client stubs w/ XFire
Axis2's wsdl2java
IBM's wsdl2java
您可以使用 SAAJ API 来实现此目的。
有关更多详细信息,请访问以下链接:
You can use SAAJ API for this purpose.
For more details visit these links:
最简单的方法是soap-ws库: https://github.com/reficio/soap-ws
The simplest way is soap-ws library: https://github.com/reficio/soap-ws