繁体   English   中英

如何将CXF Web服务使用的地址更改为与wsdl文件中指定的地址不同的地址?

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

当我根据配置获得wsdl时,我已经开始工作了,但是我想告诉它使用特定地址进行服务调用并使用wsdl的本地副本。

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

有谁知道这方面的最佳做法?

xml请求有效。

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

代理xml请求不起作用。

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

你可以使用ClientProxyFactoryBean吗? 如果您有已编译的存根,则甚至不需要WSDL。 例如:

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

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

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

JaxWS而不是FactoryBeanfactory客户端面向我们工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM