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)