overriding or setting web service endpoint at runtime for code generated with wsimport

前端 未结 2 553
时光说笑
时光说笑 2020-11-30 21:21

Using code that was generated with wsimport, can the service endpoint be overridden without having to regenerate the code?

I have written a simple java

2条回答
  •  不知归路
    2020-11-30 21:50

    Your client can set the end-point in the service "port" at runtime via the BindingProvider interface.

    Consider the JAX-WS client in this JAX-WS tutorial. Another way to write this code would be:

    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);
    

    Caveat: I haven't downloaded the tutorial code and tested this code against it.

提交回复
热议问题