`
XieGuoWei123485
  • 浏览: 65770 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Java的方法接收SOAP WebService

 
阅读更多
import javax.xml.soap.Node;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;

import org.w3c.dom.NodeList;

public class ReceiverSoapMessage
{
    public static void receiverMessage(SOAPMessage respMsg)
    {
        try
        {

            SOAPEnvelope envelope = respMsg.getSOAPPart().getEnvelope();
            // 写header
            SOAPHeader header = envelope.getHeader();
            // 写Body
            SOAPBody body = envelope.getBody();
            SOAPElement orderResponse = (SOAPElement) body.getChildElements(
                    envelope.createName("orderResponse", "uvs",
                            "http://bme.huawei.com/uvsinterface")).next();
            SOAPElement OrderResult = (SOAPElement) orderResponse
                    .getChildElements().next();
            SOAPElement ResultMessage = (SOAPElement) OrderResult
                    .getChildElements().next();
            SOAPElement MessageHeader = (SOAPElement) ResultMessage
                    .getChildElements().next();

            NodeList nodelist = (NodeList) MessageHeader.getChildNodes();
            while (nodelist.getLength() > 0)
            {
                for (int i = 0; i < nodelist.getLength(); i++)
                {
                    Node node = (Node) nodelist.item(i);
                    short Type = node.getNodeType();
                    String name = node.getNodeName();
                    String value = node.getTextContent();
                    String namespace = node.getNamespaceURI();

                    System.out.println(Type);
                    System.out.println(name);
                    System.out.println(value);
                    System.out.println(namespace);
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics