这是我的代码创建的:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isUserExists>
<userId>10</userId>
</ws:isUserExists>
</soapenv:Body>
</soapenv:Envelope>
在我的soapenv:信封中|| xmlns:soapenv来了两次
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
现在这就是我需要的:
这里
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
在SOAP请求中不存在<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/ " xmlns:ws="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isUserExists>
<userId>10</userId>
</ws:isUserExists>
</soapenv:Body>
</soapenv:Envelope>
我用来创建请求的Java代码是:
public static SOAPMessage createIsUserExistsSOAPRequest(User user) throws SOAPException
{
MessageFactory messageFactory =MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
soapMessage.getSOAPHeader().setPrefix("soapenv");
SOAPPart soapPart = soapMessage.getSOAPPart();
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.setPrefix("soapenv");
envelope.addNamespaceDeclaration("ws","http://example.com");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
soapBody.setPrefix("soapenv");
SOAPElement ensureUserExistsElem = soapBody.addChildElement("isUserExists", "ws");
SOAPElement userIdElem = ensureUserExistsElem.addChildElement("userId");
userIdElem.addTextNode(user.userId);
String authorization = new sun.misc.BASE64Encoder().encode(("[email protected]").getBytes());
MimeHeaders hd = soapMessage.getMimeHeaders();
hd.addHeader("Authorization", "Basic " + authorization);
soapMessage.saveChanges();
return soapMessage;
}
请帮忙:我做错了什么?
最佳答案
在我的soapenv:信封中|| xmlns:soapenv来了两次
它不会出现两次。您正在定义2个绑定到相同名称空间的前缀。
xmlns:soapenv =“ http://schemas.xmlsoap.org/soap/envelope/”
xmlns:SOAP-ENV =“ http://schemas.xmlsoap.org/soap/envelope/”
请帮忙:我做错了什么?
没有。命名空间前缀是soapenv
还是SOAP-ENV
或polar-bear-ninjas
都没有关系。只要将前缀绑定到名称空间,就可以完全限定该XML元素。两种XML均有效,使用哪个前缀都没有关系。