[英]Apache CXF Client for Dynamic Endpoints
我現在使用 Apache CXF 作為 .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 ,但我可以在任何地方。 當然,這個行人問題以某種方式解決了?
請嘗試以下操作:
MyWebServicesSoap port = service.getMyWebServicesSoap12();
BindingProvider provider = (BindingProvider) port;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
或者, MyWebServices
可能有其他 getXXX 方法,這些方法采用 WSDL 位置的 URL
在 cxf 2.6.1 中工作
Client client = ClientProxy.getClient(port);
client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "http://some-valid-endpoint") ;
這對我有用。
String customerEndPoint = "https://localhost:8080/customerService/v1"
customerWebService = service.getCustomerWebServicePort();
((BindingProvider) customerWebService).getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
customerEndPoint);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.