2012-08-28 33 views
0

我通過wsimport從遠程wsdl生成了存根文件,並創建了獨立客戶端。現在,當我運行的客戶端,所產生的HTTP請求是這樣的:JAX WS未生成正確的HTTP請求

HTTP標頭:

---[HTTP request - http://www.transportdirect.info/EnhancedExposedServices/CarJourneyPlannerSynchronous/v1/CarJourneyPlannerSynchronousService.asmx]--- 
Content-type: text/xml;charset="utf-8" 
Soapaction: "http://www.transportdirect.info/TransportDirect.EnhancedExposedServices.CarJourneyPlannerSynchronous.V1/GetGridReference" 
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 

HTTP正文:

<?xml version="1.0" ?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Header> 
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <wsse:UsernameToken> 
     <wsse:Username>USERNAME</wsse:Username> 
     <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password> 
     </wsse:UsernameToken> 
    </wsse:Security> 
    </S:Header> 
    <S:Body> 
    <GetGridReference xmlns="http://www.transportdirect.info/TransportDirect.EnhancedExposedServices.CarJourneyPlannerSynchronous.V1"> 
     <transactionId>bfe2ccbe-9197-4992-9073-cd3a3c0e5c47</transactionId> 
     <locationType>Postcode</locationType> 
     <locationValue>W11</locationValue> 
    </GetGridReference> 
    </S:Body> 
</S:Envelope> 

現在,SOAP信封的部分是完全沒有問題因爲我已經使用SOAP工具對其進行了測試並獲得了正確的輸出。但上面的HTTP請求總是給我

---[HTTP response - http://www.transportdirect.info/EnhancedExposedServices/CarJourneyPlannerSynchronous/v1/CarJourneyPl 
annerSynchronousService.asmx - 500]--- 
null: HTTP/1.1 500 Internal Server Error 
Cache-control: private 
X-ua-compatible: IE=EmulateIE7 
Content-type: text/html; charset=utf-8 
Content-length: 7424 
Connection: close 
X-powered-by: ASP.NET 

後面跟着大量的html標籤,描述了一些錯誤。

我的Java客戶端代碼如下 -

CarJourneyPlannerSynchronousService service = new CarJourneyPlannerSynchronousService(); 
port = service.getCarJourneyPlannerSynchronousServiceSoap(); 
port.getGridReference(transactionId, "bla-bla", "bla-bla"); 

能否請你告訴我我在這裏失蹤?請讓我知道,如果你想看到更多的代碼。上線

回答

0

關注:

HTTP/1.1 500 Internal Server Error 

這表明,在服務器端出現了問題。檢查服務器日誌,你會發現錯誤的原因。

如果您無法訪問服務器,請查看Web服務的文檔,並檢查您是否發送了一些不合適的參數,這可能導致服務器崩潰(因爲您提到您測試了SOAP請求,所以非常不可思議與其他工具)。我懷疑在soapaction場在你的HTTP頭,因爲基於.NET的Web服務通常有與它的問題 - 如果你發送一個值,他們沒有想到,你可以得到錯誤500

參考文獻:

+0

感謝Miljen。你的建議幫助我嗅探周圍。目標HTTP請求URL是錯誤的。現在,這些都是wsimport生成的java文件,除了我上面的Java代碼之外 - 代碼中的哪個位置可以更改服務URL? – somakd

+0

您可以通過(至少)兩種方式更改服務URL,看看這個很好的答案:http://stackoverflow.com/questions/2490737/how-to-change-webservice-url-endpoint –

+0

謝謝你許多。這工作! – somakd