开发者

how to develop JAX-WS webservice client?

开发者 https://www.devze.com 2023-03-23 16:29 出处:网络
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 s开

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 s开发者_如何学编程ervice. 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.


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:

<bean id="subscriptionJaxProxyService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"
 p:serviceInterface="org.krams.tutorial.oxm.SubscriptionPort"
 p:wsdlDocumentUrl="http://localhost:8081/spring-ws-standalone/krams/ws/subscription.wsdl"
 p:namespaceUri="http://krams915.blogspot.com/ws/schema/oss"
 p:serviceName="SubscriptionPortService"
 p:portName="SubscriptionPortSoap11"/>

Finally, inject a marshaller/unmarshaller through spring (e.g. Jaxb2Marshaller) to deserialize the web service's responses.

Notes:

  • make sure to check the article it mentions at the beginning:

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:

    <pluginRepository>
        <url>http://download.java.net/maven/2</url>
        <id>Java dot Net</id>
        <layout>default</layout>
        <name>Repository for JAX-WS commons</name>
    </pluginRepository>
    


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消