[英]How to add a SOAP Header using Java JAX-RPC?
我有這樣的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:
我真的被困在這里了。 親切的,有人幫幫我。
我做了很多研究,發現了我的錯誤。 我沒有傳遞Security名稱空間URL。 所以代替:
Name headerContextName = soapEnvelope.createName("MFprofileMnt", "ch","");
我把它作為:
Name headerContextName = soapEnvelope.createName("MFprofileMnt", "ch",SOAP_Security_Namespace_URL);
瞧它開始工作,沒有名稱空間錯誤。 希望這有助於遇到類似問題的其他人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.