如何开发JAX-WS Web服务客户端?
我有一个要求在使用 spring 框架的独立 java 应用程序中开发 Web 服务客户端。我的问题是如何开发一个可用于调用 Web 服务的 java 类。我所拥有的只是 WSDL 和 wsdl 文件的位置?此外,该应用程序应该在 diff envt 中运行。其中 WSDL 的 url 是 diff。所以基本上我想如果可能的话外部化 url 属性。
我听说过使用 Spring 框架中的 JaxwsproxFactoryBean,但没有找到任何好的工作示例。
I have one requirement to develop web service client in standalone java application which is using spring framework. My question is how can i develop one java class which can be used to call a web service. All I have is location of the WSDL and wsdl file? Also this application should run in diff envt. where url of the WSDL is diff. So basically I want to externalize the url property if possible.
I heard about the using JaxwsproxFactoryBean from spring framework but not finding any good working example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想使用 Spring,JaxwsProxyFactoryBean 是最佳选择。至少我做到了。
我按照这个例子:
http://krams915。 blogspot.com/2010/12/spring-mvc-3-accessing-web-services.html
我没有尝试过本文提供的确切代码,但我遵循一步一步,我成功了。而且它很简单:本例中使用 wsimport 工具来生成类,使用 JaxwsProxyFactoryBean 来注入代理:
最后,通过 spring 注入编组器/解组器(例如 Jaxb2Marshaller)来反序列化 Web 服务的响应。
注意:
http://krams915.blogspot.com/2010/12/spring-ws-mvc-implementing-client.html
最烦人的部分是wsimport 开始工作。确保使用存储库中的版本 1.12:
If you want to go with Spring, JaxwsProxyFactoryBean is the way to go. At least I did.
I followed this example:
http://krams915.blogspot.com/2010/12/spring-mvc-3-accessing-web-services.html
I have not tried the exact code provided by this article, but I followed step-by-step and I made it work. And it is hassle-free: wsimport tool is used in this example for generating the classes and JaxwsProxyFactoryBean is used to inject the proxy:
Finally, inject a marshaller/unmarshaller through spring (e.g. Jaxb2Marshaller) to deserialize the web service's responses.
Notes:
http://krams915.blogspot.com/2010/12/spring-ws-mvc-implementing-client.html
the most annoying part was to get wsimport to work. Make sure to use version 1.12, from repository:
在我看来,您不必使用 Spring 来创建 Web 服务客户端。
wsimport 工具可用于此目的。
打开命令提示符,将目录更改为 wsimport.bat / ws.import.sh 所在位置并执行以下命令。
wsimport -keep -verbose ${your wsdl location}
将在名为 com 的文件夹中(最有可能)生成几个源文件。顶层文件夹的名称取决于您在 wsdl 中使用的顶层包的名称。
In my opinion, you don't necessarily have to use Spring in order to create a web service client.
wsimport tool can be used for this purpose.
open the command prompt, change dir to where wsimport.bat / ws.import.sh is located and execute the command below.
wsimport -keep -verbose ${your wsdl location}
Several source files will have been generated (most probably )in a folder named com. The name of the top folder depends on the name of the top package you have used in your wsdl.