简体   繁体   English

如何在SOAP HEader中将子节点添加到childNode?

[英]How to add child nodes to childNode in SOAP HEader?

I am trying to create children nodes inside and it should look like the following 我正在尝试在内部创建子节点,它应如下所示

   <soapenv:Header>
       <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-21" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
           <wsse:Username>USER</wsse:Username>
           <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PAASS</wsse:Password>
           <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">==</wsse:Nonce>
           <wsu:Created>2012-02-22T16:27:29.088Z</wsu:Created>
         </wsse:UsernameToken>
       </wsse:Security>
     </soapenv:Header>

with the following 与以下

    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPElement userNameToken = envelope.getHeader().addChildElement("Usernametoken", WSSE_NS_PREFIX, WSSE_NS);
    SOAPElement user = userNameToken.addChildElement("UserName", WSSE_NS, WSSE_NS_PREFIX);

i get the following error when attemping to do so: 尝试这样做时出现以下错误:

    NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

It seems that you mixed order of arguments (WSSE_NS vs WSSE_NS_PREFIX) It should be 似乎您混合了参数的顺序(WSSE_NS与WSSE_NS_PREFIX),应该是

SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPElement userNameToken = envelope.getHeader().addChildElement("Usernametoken", WSSE_NS_PREFIX, WSSE_NS);
SOAPElement user = userNameToken.addChildElement("UserName", WSSE_NS_PREFIX, WSSE_NS);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM