【问题标题】:JAX WS not producing correct HTTP requestJAX WS 没有产生正确的 HTTP 请求
【发布时间】:2012-08-28 14:30:48
【问题描述】:

我已经通过 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 Envelope 部分完全没问题,因为我已经使用 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");

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

【问题讨论】:

    标签: jax-ws webservice-client


    【解决方案1】:

    注意就行了:

    HTTP/1.1 500 Internal Server Error
    

    表示服务器端出现问题。检查服务器日志,您将找到错误原因。

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

    参考资料:

    【讨论】:

    • 谢谢米伦。你的建议帮助我四处寻找。目标 HTTP 请求 URL 错误。现在这些都是 wsimport 生成的 java 文件,除了我上面的 Java 代码 - 我在代码中的哪里更改服务 URL?
    • 您可以通过(至少)两种方式更改服务 URL,看看这个很棒的答案:stackoverflow.com/questions/2490737/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多