0

如何从位于 SOAP 主体下的 requestHeader 获取 clientCode?

<soapenv:Body>
      <ser:GS>
         <!--Optional:-->
         <requestHeader>
            <!--Optional:-->
            <req:clientCode>KL7MU</req:clientCode>
            <!--Optional:-->
            <req:clientUsername>BLABLA</req:clientUsername>
         </requestHeader>
      </ser:GS>
   </soapenv:Body>

我试图得到但iterator.hasNext()返回false

SOAPBody soapBody = context.getMessage().getSOAPBody();

java.util.Iterator iterator = soapBody.getChildElements();
while (iterator.hasNext()) {
  SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next();
  String val = bodyElement.getValue();
  System.out.println("The Value is:" + val);
}
4

3 回答 3

1

您可以使用 wsdl 生成 java 类:

wsimport stock.wsdl -b stock.xml -b stock.xjb
wsimport -d generated http://example.org/stock?wsdl    

然后,您可以将 SOAP 服务作为本地方法调用。

其他一些工具:

wsdl2javawizard:http: //sourceforge.net/projects/wsdl2javawizard/

apache cxf:http ://cxf.apache.org/docs/wsdl-to-java.html

于 2013-09-13T08:01:16.583 回答
0

而不是获取表单 SOAP 消息体,尝试使用 SOAP 消息头中的子元素,例如 context.getMessage().getSOAPPart().getEnvelope().getHeader(); 详情:http ://www.mkyong.com/webservices/jax-ws/jax-ws-soap-handler-in-client-side/

于 2013-09-13T07:58:17.773 回答
-1

你可以得到像公理中的值,

SOAPEnvelope mes = messageContext.getEnvelope();
SOAPHeader mesh = mes.getHeader();
SOAPBody mesb = mes.getBody();
OMElement messageId = mesh.getFirstChildWithName(new QName("http://www.w3.org/2005/08/addressing","MessageID"));
String messageIDStr = messageId.getText();
OMElement bodyChild = mesb.getFirstElement();
OMElement remoteAddress = bodyChild.getFirstChildWithName(new QName(
                                    "http://YourNameSpaceURI",
                                    "remoteAddress"));
String remoteAddressStr = remoteAddress.getText();
于 2014-10-09T11:36:57.123 回答