如何使用Java JAX-RPC添加SOAP Header?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何使用Java JAX-RPC添加SOAP Header?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1790字,纯文字阅读大概需要3分钟。
内容图文
![如何使用Java JAX-RPC添加SOAP Header?](/upload/InfoBanner/zyjiaocheng/785/28079cbc553648938cf871f4ed1091fb.jpg)
我有这样的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);
瞧它开始工作,没有名称空间错误.希望这有助于遇到类似问题的其他人.
内容总结
以上是互联网集市为您收集整理的如何使用Java JAX-RPC添加SOAP Header?全部内容,希望文章能够帮你解决如何使用Java JAX-RPC添加SOAP Header?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。