我被要求使用Java生成一些SOAP ui请求。我对肥皂一无所知,所以当我独自一人的时候,我正试图解决这个问题,如果这是一个愚蠢的问题,请原谅我。
这是我试图用Java创建的请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://BT/IStore/WebServices/">
<soapenv:Header/>
<soapenv:Body>
<web:ProductSearch>
<!--Optional:-->
<web:RequestData>
<web:ChannelID>4</web:ChannelID>
<!--Optional:-->
<web:CountryID>GB</web:CountryID>
<web:HD>true</web:HD>
<web:COLLECTION>true</web:COLLECTION>
<!--Optional:-->
<web:ProductID></web:ProductID>
<web:ProductSKUs></web:ProductSKUs>
使用我在网上找到的例子,我设法创建了这样的肥皂信息:
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://BT/IStore/WebServices/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("soapenv", serverURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("VerifyEmail", "soapenv");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("email", "soapenv");
soapBodyElem1.addTextNode("mutantninja@gmail.com");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("LicenseKey", "soapenv");
soapBodyElem2.addTextNode("123");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "VerifyEmail");
soapMessage.saveChanges();
它输出的消息是节点上的名称空间“soapenv”:
<?xml version="1.0"?>
-<SOAP-ENV:Envelope xmlns:soapenv="http://BT/IStore/WebServices/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
-<SOAP-ENV:Body>
-<soapenv:VerifyEmail>
<soapenv:email>mutantninja@gmail.com</soapenv:email>
<soapenv:LicenseKey>123</soapenv:LicenseKey>
</soapenv:VerifyEmail>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如果我更改了任何元素的前缀,我会收到错误“无法找到前缀web的命名空间”,有人可以帮助我如何添加一个以web作为前缀的新节点吗?