The SOAP header is used by the general user for authentication, and the custom SOAP header is typically in 3 ways:
First: Add Simple string
---on stub
_stub = new Onepassservicesstub ("http://192.168.1.147:8080/mywebservice/services/OnepassServices?wsdl"); Omfactory omfactory =omabstractfactory.getomfactory (); Omnamespace omnamespace = Omfactory.createomnamespace ("http://mycompany.org", "MyHeader"); Omelement Header = omfactory.createomelement ("header", omnamespace); Header.settext ("This is a custom SOAP header"); _stub._getserviceclient (). AddHeader (header);
---Auditinhandler.java
SOAP message:
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>, <soapenv:envelope ' xmlns:soapenv= ' http://www.w3.org/2003/05/ Soap-envelope "> <soapenv:Header> <myheader:header xmlns:myheader=" http://mycompany.org "> This is a Custom SOAP Header </myHeader:header> </soapenv:Header> <soapenv:Body> <ns2:getuserprofile xmlns : ns2= "Http://axis.test.com/ws"/> </soapenv:Body> </soapenv:Envelope>
<myheader:header xmlns:myheader= "http://mycompany.org" >
This is a custom SOAP header
</myHeader:header>-----------------------------------------------------------Custom Header
Second: Encapsulate the SOAP header with Omelement object
---on stub
Omelement header1 = axiomutil. Stringtoom ("
---SOAP message
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>, <soapenv:envelope ' xmlns:soapenv= ' http://www.w3.org/2003/05/ Soap-envelope "> <soapenv:Header>
The third type: Soapheaderblock
---on stub
Omnamespace omnamespace = Omabstractfactory.getomfactory (). Createomnamespace ("http://myCompany.com", "headerns"); Soapheaderblock header1 = Omabstractfactory.getsoap12factory (). Createsoapheaderblock ("Header1", omnamespace); Header1.addchild (Axiomutil.stringtoom ("
---SOAP message
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>, <soapenv:envelope ' xmlns:soapenv= ' http://www.w3.org/2003/05/ Soap-envelope "> <soapenv:Header>
Note that if you want to obtain the custom SOAP header in response, you can customize the module method to refer to the way of the previous article.