Thursday, February 24, 2011

Consuming same WSDL from different end points/hosts without reloading

We have a device which can be controlled using web service described by a WSDL. We have hundreds of similar device to be controlled from a software. All devices exposes same WSDL but only hostname is changed. While using Java's wsimport generated client API, we need to pass WSDL location and all subsquent call are done to the location defined by this WSDL. As we need to manage multiple devices, we need to initiate API with different WSDL location. This involves loading, parsing of WSDL for each device even its same for all. To avoid this, we can use approach described in following article

https://issues.jboss.org/browse/JBWS-2379

We statically create service from a WSDL and than override host info for each call for aparticular host as follows
Service service = (Service) Service.create(wsdlURL, serviceQName);

port = service.getPort(MyServiceApi.class);

BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"http://10.95.14.134/soap");

here the value should be same as defined in the location for port in service


No comments:

Post a Comment