Java axis calls a. NET WebService with a SOAP header (SoapHeader)

Source: Internet
Author: User

Using axis to call the. NET band SoapHeader WebService is implemented, and now the code is posted

<?xml version= "1.0" encoding= "Utf-8"? ><soap:envelope xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "xmlns:soap=" http://schemas.xmlsoap.org/soap/ envelope/">  <soap:Header>  <authheadercs xmlns=" http://tempuri.org/">      <username >string</Username>      <Password>string</Password>    </AuthHeaderCS>  </ soap:header>  <soap:Body>    <startrans xmlns= "http://tempuri.org/"/>  </soap:Body> </soap:Envelope>
View Code

Importjava.rmi.RemoteException;ImportJavax.xml.namespace.QName;ImportJavax.xml.rpc.ParameterMode;Importjavax.xml.rpc.ServiceException;Importjavax.xml.soap.SOAPException;ImportOrg.apache.axis.client.Call;ImportOrg.apache.axis.client.Service;ImportOrg.apache.axis.encoding.XMLType;Importorg.apache.axis.message.SOAPHeaderElement; Public classaa{ Public Static voidMain (string[] args)throwsserviceexception, remoteexception {Try        {            //the URL of the server, which needs to be changed according to the situation. String Endpointurl = "HTTP://192.168.0.209:7080/DATASHAREWEBSERVICE.ASMX?WSDL"; Service Service=NewService (); Call Call=(call) Service.createcall (); Call.settargetendpointaddress (NewJava.net.URL (Endpointurl)); Call.setsoapactionuri ("http://tempuri.org/" + "Startrans"); Call.setoperationname (NewQName ("Datasharewebservice", "Startrans"));//sets the name of the action. //because authentication is required, the user name and password for the call need to be set. Soapheaderelement soapheaderelement =NewSoapheaderelement ("http://tempuri.org/", "Authheadercs"); Soapheaderelement.setnamespaceuri ("http://tempuri.org/"); Try{soapheaderelement.addchildelement ("Username"). SetValue ("admin")); Soapheaderelement.addchildelement ("Password"). SetValue ("123")); }            Catch(SoapException e) {e.printstacktrace ();            } call.addheader (Soapheaderelement); Call.setreturntype (xmltype.xsd_string);//The data type returnedCall.addparameter ("Op1", xmltype.xsd_string, parametermode.in);//Types of Parametersstring ret = (string) Call.invoke (NewObject[] {"11111"});//Execute CallSystem.out.println (ret); }        Catch(Exception e) {e.printstacktrace (); }    }}
View Code

Java axis calls a. NET WebService with a SOAP header (SoapHeader)

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.