I have generated stub for a webserivce using apache axis2 and I want to add custom soap header to the request. I want the soap header to look like this
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
开发者_StackOverflow社区<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>
and I am writing this code
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);
but I am not getting the required soap header. This is what im getting
<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>
as you can see password is missing. I want to know what I am doing wrong.
精彩评论