Let say you have a wsdl that you get from an url, but you want to fire the webservice generated from it to a different url, see my code below for example,
<service name="TestingService"> <port name="TestingServicePort" binding="tns:TestingServicePortBinding"> <soap:address location="http://localhost:8084/WSDLTest/TestingService" /> </port> </service>
as you can see, my wsdl is pointing at “http://localhost:8084/WSDLTest/TestingService”. But what if i want to fire my webservice client into another url, without changing the original wsdl. For example, my new url would be http://192.168.0.101/WSDLTest/TestingService.
Well, it’s actualy quite easy. All you need to do is only casting the service interface into interface BindingProvider, and add a new url property. This is what my code would look like,
TestingService_Service tss = new TestingService_Service(); TestingService testingService = tss.getTestingServicePort(); ((BindingProvider) testingService).getRequestContext() .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://192.168.0.101/WSDLTest/TestingService");
If you fire your service again, it will point to a new url (http://192.168.0.101/WSDLTest/TestingService) instead of the old one (http://localhost:8084/WSDLTest/TestingService).