How do I change the address used by a CXF Web Service to one different than the one specified in the wsdl file?

自古美人都是妖i 提交于 2019-12-22 10:22:54

问题


I've got it working when I get the wsdl based on configuration, but I'd like to just tell it to use a specific address for the service call and use a local copy of the wsdl.

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

Does anyone know the best practice for this?

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>

proxy xml request that doesn't 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>

回答1:


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

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



回答2:


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

((BindingProvider)service).getRequestContext()
    .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/foobar");



回答3:


JaxWsProxyFactoryBeanfactory = new JaxWsProxyFactoryBean();

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

JaxWS instead of Client infront of FactoryBeanfactory worked for us.



来源:https://stackoverflow.com/questions/1421873/how-do-i-change-the-address-used-by-a-cxf-web-service-to-one-different-than-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!