JAX WS未生成正确的HTTP请求



我已经通过wsimport从远程wsdl生成了存根文件,并创建了一个独立的客户端。现在,当我运行客户端时,产生的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");

你能告诉我我这里缺了什么吗?如果您想查看更多代码,请告诉我。

注意这一行:

HTTP/1.1 500 Internal Server Error

这表明服务器端出现了问题。检查服务器日志,您会发现错误的原因。

如果您没有访问服务器的权限,请查看Web服务的文档,并检查您是否发送了一些可能导致服务器崩溃的不适当参数(这是非常不可能的,因为您提到使用其他工具测试了SOAP请求)。我怀疑您的HTTP标头中的soapaction字段,因为基于.NET的Web服务经常会遇到问题——如果您发送了他们不期望的值,则可能会得到错误500。

参考文献:

  • http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/
  • https://sharepoint.stackexchange.com/questions/43543/how-to-debug-500-internal-server-error-when-calling-web-services

最新更新