如何使用Java中的Webservice SOAP请求和响应包含标头和主体
我有来自我们必须使用其服务的银行的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 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