【问题标题】:How to add a SOAP Header using Java JAX-RPC?如何使用 Java JAX-RPC 添加 SOAP 标头?
【发布时间】:2012-12-26 14:58:16
【问题描述】:

我有一个这样的 SOAP 请求:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ch="urn://mfots.com/xmlmessaging/CH" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soapenv:Header>
<ch:MFprofileMnt>
<ch:myID>1458</ch:myID>
<ch:bigID>raptool</ch:bigID>
<ch:matID>5689</ch:matID>
</ch:MFprofileMnt>

现在我像这样在 java 中创建了请求:

        Name headerContextName = soapEnvelope.createName("MFprofileMnt", "ch","");
        SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(headerContextName);
        // mustUnderstand attribute is used to indicate
        // whether the header entry is mandatory or optional for the
        // recipient to process.
        soapHeaderElement.setMustUnderstand(true);
        //Now set the attribute children
        // create the first child element and set the value
        SOAPElement element1 = soapHeaderElement.addChildElement("myID", "ch");
        element1.setValue("1458");
        //create the second child element and set the value
        SOAPElement element2 = soapHeaderElement.addChildElement("bigID", "ch");
        element2.setValue("raptool");
        //create the third child element and set the value
        SOAPElement element3 = soapHeaderElement.addChildElement("matID", "ch");
        element3.setValue("5689");

但是,当我运行程序时,我不断收到这些错误:

org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
faultActor: null
faultDetail:

我真的被困在这里了。请有人帮助我。

【问题讨论】:

    标签: java web-services jax-rpc


    【解决方案1】:

    我做了很多研究,发现了我的错误。我没有传递安全命名空间 URL。所以而不是:

    Name headerContextName = soapEnvelope.createName("MFprofileMnt", "ch","");
    

    我给了它:

    Name headerContextName = soapEnvelope.createName("MFprofileMnt", "ch",SOAP_Security_Namespace_URL);
    

    瞧,它开始工作并且没有命名空间错误。希望这对遇到类似问题的其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 2010-10-24
      • 2011-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-21
      • 2011-05-02
      • 2016-08-23
      • 2020-10-28
      相关资源
      最近更新 更多