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