首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Java的步骤接收SOAP WebService

2012-09-06 
Java的方法接收SOAP WebServiceimport javax.xml.soap.Nodeimport javax.xml.soap.SOAPBodyimport javax

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();
        }

    }
}

热点排行