How do I change the address used by the CXF web service to another than the one specified in the wsdl file?

It works for me when I get wsdl based on the configuration, but I would just tell him to use a specific address to call the service and use a local copy of wsdl.

MyWebService serviceDefinition = new MyWebService(new URL(wsdlLocation));
service = serviceDefinition.getMyWebServicePort();

Does anyone know this best?

xml request that works.

<soap:Body>
<ns2:getData xmlns:ns2="http://services.test.com/">
<arg0>Test Name</arg0>
<arg1>55555555</arg1>
</ns2:getData>
</soap:Body>

xml proxy request that does not work.

<soap:Body>
<ns1:getData xmlns:ns1="http://ws.test.com/">
<ns3:arg0 xmlns:ns2="http://services.test.com/" xmlns:ns3="http://ws.test.com/">Test Name</ns3:arg0>
<ns3:arg1 xmlns:ns2="http://services.test.com/" xmlns:ns3="http://ws.test.com/">55555555</ns3:arg1>
</ns1:getData>
</soap:Body>
+3
source share
3 answers

Can you use ClientProxyFactoryBean ? You don't even need WSDL if you have compiled stubs. For example:

ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(HelloWorld.class);
factory.setAddress("http://localhost:9000/Hello");
HelloWorld client = (HelloWorld) factory.create();
+9
source
MyWebService serviceDefinition = new MyWebService(new URL(wsdlLocation));
service = serviceDefinition.getMyWebServicePort();

((BindingProvider)service).getRequestContext()
    .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/foobar");
+5
source
JaxWsProxyFactoryBeanfactory = new JaxWsProxyFactoryBean();

factory.setServiceClass(HelloWorld.class);
factory.setAddress("http://localhost:9000/Hello");
HelloWorld client = (HelloWorld) factory.create();

JaxWS infront FactoryBeanfactory .

+3

Source: https://habr.com/ru/post/1717655/


All Articles