如何動態更改我的JAXWS客戶端使用的地址? 此客戶端由wsimport生成。JAXWS - 如何更改端點地址
回答
使用Apache CXF解決了這個問題。
只有兩行代碼!以下是代碼片段:
URL url_wsdl = new URL("http://myserver/myservice?wsdl");
Service service = Service.create(url_wsdl, new QName("http://myaddress...", "ServiceName"));
return service.getPort(MyJAXWSPortClass.class);
這確實/應該工作,但是構建像這樣的新服務對象不是一個好的解決方案。它會導致WSDL從新端點重新分析,並且執行起來非常昂貴。 @麥克道威爾的引用帖子是做它被問到的最好的方法:http://stackoverflow.com/questions/3569075/jaxws-service-client –
@HelterScelter:同意,但在某些情況下,這個價格是可以忽略的,例如當應用程序只需要在啓動時映射此端口一次。 –
它只在服務器「http:// myserver/myservice?wsdl」在線時才起作用。 如果你有幾個應用程序,這意味着按照直接定義的順序部署它們,這可能是一個問題(甚至在循環依賴的情況下也是不可能的) – GKislin
我不確定如何使用wsimport。我有同樣的問題,所以我使用Intellij IDEA(版本9)爲我創建客戶端代碼。它提供了一個接受wsdl url的服務端點構造函數。
我正在尋找使用wsimport的解決方案。無法使用Intellij IDEA –
您可以使用BindingProvider接口來實現該功能。
/**
* The following snippets shows how to set a custom endpoint for a JAX-WS generated WebClient on runtime
*/
// Get the service and the port
SampleService service = new SampleService();
Sample port = service.getESamplePort();
// Use the BindingProvider's context to set the endpoint
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.aviramsegal.com/ws/sample");
/* Optional credentials */
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "user");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
port.callSampleMethod();
我是新來的PayPal的整合,我不知道關於自適應支付API。 但我們有權檢查是否在PayPal中使用GetVerifiedStatus方法的特定電子郵件ID。
請使用以下沙箱WSDL URL驗證電子郵件
網址:https://svcs.sandbox.paypal.com/AdaptiveAccounts?wsdl
響應會像下面
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns2:GetVerifiedStatusResponse xmlns:ns2="http://svcs.paypal.com/types/aa">
<responseEnvelope>
<timestamp>2015-07-20T23:42:46.661-07:00</timestamp>
<ack>Success</ack>
<correlationId>5cea9a8575ab9</correlationId>
<build>17345626</build>
</responseEnvelope>
<accountStatus>UNVERIFIED</accountStatus>
<countryCode>IN</countryCode>
<userInfo>
<emailAddress>[email protected]</emailAddress>
<accountType>PERSONAL</accountType>
<accountId>6KD7EVWM2E2AQW</accountId>
<name>
<salutation/>
<firstName>anand</firstName>
<middleName/>
<lastName>anand</lastName>
<suffix/>
</name>
<businessName/>
</userInfo>
</ns2:GetVerifiedStatusResponse>
</soapenv:Body>
</soapenv:Envelope>
注:創建存根不要忘了如下設置終點。 如果我們沒有設置這個,我們不能得到預期的輸出。以下方法
String endpointURL = "https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus";
使用添加端點
private static void addEndPoint(AdaptiveAccountsPortType port,
String endpointURL) {
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
/*List hchain = bp.getBinding().getHandlerChain();
if (hchain == null) {
hchain = new ArrayList();
}
hchain.add(new HTTPUserAgentHandler());
bp.getBinding().setHandlerChain(hchain);*/
}
- 1. CXF jaxws端點相對發佈地址
- 2. SoapUI更改端點地址
- 3. WSO2 ESB:動態更改端點地址
- 4. 如何更改多個測試的端點地址?
- 5. 如何在客戶端網站中以編程方式更改端點地址?
- 6. 如何更改地址欄?
- 7. jaxws web服務。更改節點結構
- 8. InstantiationException:java.math.BigDecimal中在JAXWS:端點
- 9. 如何更改Spring JaxWs代理的端口?
- 10. WCF端點地址
- 11. Java axis1.X客戶端更改地址
- 12. 使用行爲動態更改WCF端點地址
- 13. 在端點配置上更改IP地址
- 14. 在運行時更改WebService端點地址
- 15. 更改Sony相機遠程API端點URL的IP地址
- 16. jaxws:客戶端地址屬性不解決佔位符
- 17. 如何更改ngrok的Web界面端口地址(不是4040)?
- 18. 如何在客戶端的IP地址更改
- 19. WCF端點地址問題
- 20. WCF端點的基地址
- 21. wcf端點相對地址
- 22. 端點地址問題
- 23. 更改mac地址
- 24. 更改MAILTO地址
- 25. 如何更改eve的IP地址?
- 26. 如何更改ASP.NET中的URL地址?
- 27. 如何更改服務參考地址?
- 28. 如何更改文檔庫的地址?
- 29. 如何更改char *的內存地址?
- 30. 如何更改默認的URL地址
見http://stackoverflow.com/questions/649019/how-do-i-specify-host-and-port-when-accessing- a-web-service-from-jax-ws-generated –
*動態*表示*在運行時*? –
請參閱http://stackoverflow.com/questions/3569075/jaxws-service-client – McDowell