Changing the URL on a webservice client generated with wsimport

前端 未结 2 735
轻奢々
轻奢々 2021-01-02 01:52

I am trying to write a module for a Java application that accesses a WSDL-described webservice. The source WSDL was downloaded straight from what I believe to be an ASP.NET

2条回答
  •  执笔经年
    2021-01-02 02:23

    This approach requires me to also supply a javax.xml.namespace.QName object, which I don't yet understand, as the second argument.

    Copy the one from your generated source. A QName is an XML qualified name - a "unique" identity.

    I still don't understand why the WSDL is needed at runtime.

    I can't say I know for sure, but a WSDL is basically a schema. By providing it, I'm guessing you give JAX-WS a mechanism to validate the SOAP response. I don't think the JAXB bindings are enough to do this.

    I always use the two-argument constructor in the generated service to provide a URL via the ClassLoader.getResource method to embed the WSDL in my jar. As with any schema, using a remote or file system URL for this is stupid less than optimal.

    See this question for how to set the end-point at runtime:

    HelloService service = new HelloService();
    Hello port = service.getHelloPort();
    BindingProvider bindingProvider = (BindingProvider) port;
    bindingProvider.getRequestContext().put(
          BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
          "http://foo:8086/HelloWhatever");
    String response = port.sayHello(name);
    

提交回复
热议问题