Java2wsdl+axis2+hibernate Development WebService Learning (3)-Custom SOAP Header__web

Source: Internet
Author: User
Tags soap

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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.