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

用于动态端点的Apache CXF客户端

  •  26
  • andyczerwonka  · 技术社区  · 14 年前

    我现在使用ApacheCXF作为.NET服务的Web服务客户机来绕过NTLM身份验证。它工作得很好,但我想知道为什么我不能设置Web服务目标端点。CXF在运行时似乎想要WSDL,原因有些奇怪——不确定。它从WSDL中获取物理端点,我想在测试环境中可以很好地工作,但是在部署时它肯定会改变。

    下面是一些要演示的代码:

            MyWebServices service = new MyWebServices ();
            MyWebServicesSoap port = service.getMyWebServicesSoap12();
    
            // Turn off chunking so that NTLM can occur
            Client client = ClientProxy.getClient(port);
            HTTPConduit http = (HTTPConduit) client.getConduit();
            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
            httpClientPolicy.setConnectionTimeout(36000);
            httpClientPolicy.setAllowChunking(false);
            http.setClient(httpClientPolicy);
    
            port.doSomethingUseful();
    

    同样,在cxf客户机API中,我看不到允许我设置服务端点的地方。反正我也看不到。在这种情况下,目标是 http://localhost/integration/webservices/mywebservices.asmx 但是我可以在任何地方。这个行人问题一定是以某种方式解决了吗?

    2 回复  |  直到 6 年前
        1
  •  44
  •   Kevin    14 年前

    尝试以下操作:

    MyWebServicesSoap port = service.getMyWebServicesSoap12();
    BindingProvider provider = (BindingProvider) port;
    provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint); 
    

    或者, MyWebServices 可能还有其他的getxxx方法,它们使用WSDL位置的URL

        2
  •  11
  •   Shahzad Mughal    12 年前

    在CXF 2.6.1中工作

    Client client = ClientProxy.getClient(port);
    client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "http://some-valid-endpoint") ;