Java calls. NET WebService through axis

Source: Internet
Author: User

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

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.