June 22, 2013

Changing End point address of web service


Below code explains how to change the web service end point through program. 

ServiceRequestService serviceRequestService = new ServiceRequestService();
ServiceRequestPortType serviceRequestPortType =
serviceRequestService.getServiceRequestPortType(); 
BindingProvider bp = (BindingProvider)serviceRequestPortType;           
bp.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://localhost:9950/soa-infra/services/default/sr_v2/ServiceRequest.service");

 Here is the explanation for this code.
  • Get port object of the web service
  • Type cast the port object to BindingProvider object 
  • BindingProvider class provides a member method getRequestContext() which returns a map
  • This map holds all the attributes of the request context
  • Overwrite end point with new web service url which will replace the new end point with the old one.
Note: This code works only if the client style is RPC.

No comments:

Post a Comment