Import java.net.url;import javax.xml.namespace.qname;import javax.xml.rpc.parametermode;import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis.encoding.xmltype;import org.apache.axis.message.soapheaderelement;public class Mapwebservices { public static void main (String[] args) { String soapaction = "http://xxxx.xxxx.xxx/xsd"; string endpoint = "http// Xx.xxx.xx.xxx:8080/xxxxxx/services/xxxs "; service service = new service (); try { Call call = (call) service.createcall (); call.settimeout (New integer (60000)); call.settargetendpointaddress (new URL (endpoint)); call.setoperationname (New qname (soapaction, "getxxxx"); soapheaderelement headerelemenT = new soapheaderelement (soapaction, "Authheadercs"); Headerelement.setnamespaceuri (SOAPAction); headerelement.addchildelement ("username"). SetValue ("xxxx"); headerelement.addchildelement ("Application"). SetValue ("xxxx"); Headerelement.addchildelement ("department"). SetValue ("testdept"); call.addheader ( headerelement); call.setreturntype (xmltype.xsd_string); Call.addparameter ("O", xmltype.xsd_string, parametermode.in); string ret = (String) call.invoke (new object[] { null }); SYSTEM.OUT.PRINTLN (ret); } catch (exception e) { E.printstacktrace (); } }}
It is important to note that when you pass a value, it is not the previous
Call.addparameter ("O", xmltype.xsd_string, parametermode.in);
You need to save the parameter to Soapheaderelement and then call.addheader it.
Soapheaderelement headerelement = new Soapheaderelement (SOAPAction, "Authheadercs"); Headerelement.setnamespaceuri (SOAPAction); Headerelement.addchildelement ("username"). SetValue ("xxxx"); Headerelement.addchildelement ("Application"). SetValue ("Xxxx"); Headerelement.addchildelement ("department"). SetValue ("testdept"); Call.addheader (headerelement);
Java calls. NET WebService through axis