Consuming web services with Spring framework is amazingly easy. It avoids the need of creating client side stubs during compile time and does the same at run time. A typical web service client can be configured as shown below-
<bean id="myWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">Where serviceInterface is the business interface that clients will use for invoking service methods. wsdlDocumentUrl is the URL for the published WSDL file. Spring will download WSDL from the given URL and generate the client side stubs when it creates the bean usually during application start up. namespaceUri corresponds to the targetNamespace in the .wsdl file. serviceName corresponds to the service name in the .wsdl file. portName corresponds to the port name in the .wsdl file.
<property name="serviceInterface" value="pkg.MyService"/>
<property name="wsdlDocumentUrl" value="http://localhost:8080/testws/myService?wsdl"/>
<property name="namespaceUri" value="http://com.pkg/"/>
<property name="serviceName" value="MyService"/>
<property name="portName" value="MyServicePort"/>
</bean>
Now accessing web service pretty easy, just get the bean from Spring context and use that to invoke methods-
MyService myService = springContext.getBean("myWebService");
myService.someMethod(. . .);One downside of this approach is that the web service must be up running when consumer application is being deployed. To avoid this problem one can use lazy-init="true" to lazily initialize the beans when they are first requested but all this quickly becomes unmanageable when we have an array of SOA based applications. In such a scenario one have to strictly follow the order of application deployment else deployment might fail.

10 Comments:
Hello Vinod,
I tried using this but no success yet.
I am getting an exception saying:
org.springframework.remoting.jaxws.JaxWsSoapFaultException: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
Can you please let me know how do I solve this exception?
I am using the example service from http://www.webservicex.com/ValidateEmail.asmx?WSDL.
Thanks
Sri
Thanks & Regards
Srikanth
Sri,
If you can show the code, then I may have a look at that.
hi vinod ,
i am using the same but getting the Qname not null erorr while creating the Bean.
can you please suggest.
Hi Vinod,
I want to ask silly question :D, what is it mean by serviceInterface property, I mean what should I put as the value in there, is it the interface in the web service server or we should create another class in the client as the value?
Thanks,
Btw, I wonder with the packaging also...
Thanks,
serviceInterface is the interface, based on that JaxWsPortProxyFactoryBean will create a proxy. You need to create it to consume the web service. See here for more details.
Owh I think Im missing one step here...CMIIW i have to build jar of my web service first? import is as library in the client, then the serviceInterface will point to that jar, is that correct? I think that spring reference, must be read throughly...T.T
Hi Vinod,
I think I am missing something here, the question is also about the Service interface. I am supposed to consume .Net service. I cannot bundle the interface in a jar. Do I need to redefine the C# interface on the Client?
Spring Doc is too vague at least for me. Your help is really appreciated. thanks
You need to create that interface and related POJOs manually to consume the service through Spring.
Instead of using Spring, I prefer to consume a web service by creating client side stubs. See step #6 and 7 in Building JAX-WS web service.
Hi Vinod,
I did the similar example explained above but i stuck with below error.
Caused by: org.xml.sax.SAXException: Deserializing parameter 'Output': could not find deserializer for type {https://xxx083c1.svr.us.abc.net/UsrControlRoom/wsdl/linkAction}Output
at org.apache.axis.message.RPCHandler.onStartChild(RPCHandler.java:277)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
Any idea how to keep deserializer for Output in Spring based WS call?
Thanks,
Laks.
Post a Comment