Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instantiate JAX-WS service without downloading WSDL?

I have a web service that I have JAX-WS generated client bindings as below:

// web service client generated by JAX-WS
@WebServiceClient( ... )
public class WebService_Service extends Service {

    public WebService_Service(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    WebService getWebServiceSOAP() {
        // ...
    }
}

I want to be able to create an instance of this that points to a remote service like:

WebService_Service svc = new WebService_Service(
    new URL("http://www.example.com/ws?wsdl"),
    new QName("http://www.example.com/ws", "WebService"));

But that downloads the WSDL from http://www.example.com/ws?wsdl which I don't want to do.

Is there a way to stop the downloading of that WSDL, but still point to that same endpoint?

like image 437
oconnor0 Avatar asked Nov 10 '11 20:11

oconnor0


1 Answers

I resolved this by specifying null for the WSDL URL in the client, as well as specifying the endpoint address explicitly:

WebService_Service svc = new WebService_Service(
  null,
  new QName("http://www.example.com/ws", "WebService"));
WebService port = svc.getPort(WebService.class);
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
  .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
    "http://www.example.com/real_endpoint_url_goes_here");

See: http://shrubbery.homeip.net/c/display/W/Consuming+a+Web+Service+with+Java+6+and+JAX-WS#ConsumingaWebServicewithJava6andJAX-WS-IgnoringtheWSDLCompletely

like image 72
Joshua Davis Avatar answered Oct 22 '22 02:10

Joshua Davis