Java calls. NET WebService and axiswebservice through axis

Source: Internet
Author: User

Java calls. NET WebService and axiswebservice through axis

We have recorded the call to webservice through axis, which was docked yesterday. NET interface, it is found that the parameter passing method is different from the general parameter passing method, solved with the help of the interface buddy. Haha.

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();  } }}

When transferring values, you must note whether it is earlier.

call.addParameter("o", XMLType.XSD_STRING, ParameterMode.IN);

You need to save the parameter to SOAPHeaderElement, and then call. addHeader.

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);

 

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.