如何使用Java中的Webservice SOAP请求和响应包含标头和主体

发布于 2024-11-17 07:09:22 字数 1637 浏览 3 评论 0原文

我有来自我们必须使用其服务的银行的 WSDL 文件。使用 Apache axis 1.4 - WSDL2JAVA,我生成了所有代理文件。

我必须调用 4 个方法。每个方法的 SOAP 1.1 请求和响应都包含 Header 和 body。在请求中,标头用于设置要登录的数据,正文包含一个对象 params 来实际传递我的方法 getCat 的参数。在响应中,我有 header_out ,它向我传递连接状态、ErrorCode(用于身份验证)和正文,其中包含类似内容

 <GetCatResponse xmlns="WebServices">
  <GetCatResult>
    <xsd:schema>schema</xsd:schema>xml</GetCatResult>
</GetCatResponse>

有人可以告诉我如何编写客户端代码来发送请求并获取的回应。

肥皂如下所示。

 SOAPAction: "WebServices/GetCat"
  <soap:Envelope ....>
   <soap:Header>
    <ws_Header xmlns="WebServices">
     <sWebUser>string</sWebUser>
      <sWebPassword>string</sWebPassword>
      <sCompanyID>string</sCompanyID>
     </ws_Header>
    </soap:Header>
   <soap:Body>
     <GetCat xmlns="WebServices">
      <ObjParms>
       <sCountry>string</sCountry>
       <sCatType>string</sCatType>
       </ObjParms>
     </GetCat>
    </soap:Body>
  </soap:Envelope>

回复

<soap:Envelope ...>
<soap:Header>
  <ws_Header_Out xmlns="WebServices">
   <sFlagStatus>int</sFlagStatus>
   <sErrorCode>string</sErrorCode>
  </ws_Header_Out>
</soap:Header>
<soap:Body>
  <GetCatResponse xmlns="WebServices">
    <GetCatResult>
     <xsd:schema>schema</xsd:schema>xml</GetCatResult>
   </GetCatResponse>
 </soap:Body>
</soap:Envelope>

I have the WSDL file from the bank whose service we have to consume. Using Apache axis 1.4 - WSDL2JAVA, I have generated all the proxy files.

There are 4 methods I have to call. Each method's SOAP 1.1 request and response contains a Header and body in them. In the request, the header is used to set the data to login and the body contains a object params to actually passe the parameters for my method getCat. In the response, I have the header_out which passes me the connection Status, ErrorCode (for authentication) and body contains something like

 <GetCatResponse xmlns="WebServices">
  <GetCatResult>
    <xsd:schema>schema</xsd:schema>xml</GetCatResult>
</GetCatResponse>

Can any one tell me how I can write the client code to send the request and get the response.

Soap looks like below.

 SOAPAction: "WebServices/GetCat"
  <soap:Envelope ....>
   <soap:Header>
    <ws_Header xmlns="WebServices">
     <sWebUser>string</sWebUser>
      <sWebPassword>string</sWebPassword>
      <sCompanyID>string</sCompanyID>
     </ws_Header>
    </soap:Header>
   <soap:Body>
     <GetCat xmlns="WebServices">
      <ObjParms>
       <sCountry>string</sCountry>
       <sCatType>string</sCatType>
       </ObjParms>
     </GetCat>
    </soap:Body>
  </soap:Envelope>

RESPONSE

<soap:Envelope ...>
<soap:Header>
  <ws_Header_Out xmlns="WebServices">
   <sFlagStatus>int</sFlagStatus>
   <sErrorCode>string</sErrorCode>
  </ws_Header_Out>
</soap:Header>
<soap:Body>
  <GetCatResponse xmlns="WebServices">
    <GetCatResult>
     <xsd:schema>schema</xsd:schema>xml</GetCatResult>
   </GetCatResponse>
 </soap:Body>
</soap:Envelope>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网白 2024-11-24 07:09:22

您可以使用 eclipse 生成 webservice 客户端代码。您给它一个 WSDL(或其位置),它将为您生成所有代理。请参阅本教程

You can use eclipse to generate webservice client code. You give it a WSDL (or the location of it) and it will generate all the proxies for you. See this tutorial

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文