问题
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