Sunday, December 07, 2008

Locally packaged WSDL

As discussed in my earlier post Consuming web services with Spring, web service client initialization might fail due to non-availability of the running web service. We can overcome this limiting factor by packaging the WSDL with client and using that for creating the instance of client stub and during service method invocation use the live URL of the service. Have a look at Packaging dynamic resources with Maven to know more about packaging. The following code snippet shows how to use locally packaged WSDL and live service URL-

// during instantiation use the locally packaged WSDL
WebServiceClient ann = AddressService.class.getAnnotation(WebServiceClient.class);  
URL wsdlURL = this.getClass().getResource("/wsdl/AddressService.wsdl");

AddressService serviceObj = new AddressService(wsdlURL, new QName(ann.targetNamespace(),;
Address service = serviceObj.getAddressPort();
BindingProvider bp = ((BindingProvider) service);
Map<String, Object> context = bp.getRequestContext();

// set the live URL of the service, which will be used during service method invocations


Anonymous said...

I am trying this, but It keeps returning null wsdlURL. My webservice client is a part of a web application. I am calling the client from a servlet.
I have a question:


The location I am passing to getResource is the location of the wsdl file in .war file. But It keeps returning null URL. Am I doing it wrong?

Anonymous said...

getResource("") method returns null as it can't find the resource at the given location. You need to find the correct path of the resource.

Anonymous said...

I got it working. I was not packaging it under classes which is why it couldn't find.

Deep blog's said...

Hi vinod,

I tried this way to access the local wsdl. i get different error, details are as follows: org.apache.axis2.AxisFault: Address information does not exist in the Endpoint Reference (EPR).The system cannot infer the transport mechanism. >>>

Can you give some idea why i m getting this error