代码之家  ›  专栏  ›  技术社区  ›  ScArcher2

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

  •  3
  • ScArcher2  · 技术社区  · 16 年前

    当我得到基于配置的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>
    
    3 回复  |  直到 12 年前
        1
  •  9
  •   Kevin    16 年前

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

    ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
    factory.setServiceClass(HelloWorld.class);
    factory.setAddress("http://localhost:9000/Hello");
    HelloWorld client = (HelloWorld) factory.create();
    
        2
  •  5
  •   Alex Rashkov    12 年前
    MyWebService serviceDefinition = new MyWebService(new URL(wsdlLocation));
    service = serviceDefinition.getMyWebServicePort();
    
    ((BindingProvider)service).getRequestContext()
        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/foobar");
    
        3
  •  3
  •   so_mv    15 年前
    JaxWsProxyFactoryBeanfactory = new JaxWsProxyFactoryBean();
    
    factory.setServiceClass(HelloWorld.class);
    factory.setAddress("http://localhost:9000/Hello");
    HelloWorld client = (HelloWorld) factory.create();
    

    JAXWS 而不是 顾客 工厂前豆工厂为我们工作。