将自定义Soap标头添加到Web服务请求

时间:2011-08-11 07:13:09

标签: java web-services axis2 webservice-client wsdl2java

我使用apache axis2为webserivce生成了存根,我想在请求中添加自定义soap标头,我希望soap header看起来像这样

<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><ns1:soapHeader xmlns:ns1="urn:oasis:names:core" soapenv:mustUnderstand="0"><ns1:Username>myuser</ns1:Username><ns1:Password>mypass</ns1:Password></ns1:soapHeader></soapenv:Header>

即时编写此代码

org.apache.axiom.soap.SOAPEnvelope env = null;    
org.apache.axiom.om.OMFactory omFactory = org.apache.axiom.om.OMAbstractFactory.getOMFactory();



                                    org.apache.axiom.om.OMElement omElement = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "soapHeader", "ns1"));
                                    org.apache.axiom.om.OMElement omElement1 = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "Username", "ns1"));
                                    org.apache.axiom.om.OMElement omElement2 = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "Password", "ns1"));

                                    omElement.addChild(omElement1);
                                    omElement.addChild(omElement2);

                                    omElement1.setText("myuser");
                                    omElement2.setText("mypass");

                                    addHeader(omElement,env);

但我没有得到必需的肥皂标头,这就是我得到的

 <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><ns1:soapHeader xmlns:ns1="urn:oasis:names:core" soapenv:mustUnderstand="0"><ns1:Username>myuser</ns1:Username></ns1:soapHeader></soapenv:Header>

因为你可以看到密码丢失,我想知道我做错了什么

0 个答案:

没有答案