• Java通过axis调用.NET WebService


    前面已经记录过通过axis调用webservice,昨天在对接.NET接口时,发现在传递参数时和一般的传参方法是不一样的,在接口方哥们的帮助下解决了。哈哈。

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

    在传值时需要注意的是不是以前的

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

    需要将参数存到SOAPHeaderElement中,然后再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);
  • 相关阅读:
    Codeforces Round #547 F1&F2. Same Sum Blocks(贪心)
    Codeforces Round #547 D. Colored Boots(贪心)
    Codeforces Round #547 C. Polycarp Restores Permutation(二分枚举/数学+模拟)
    CCF 201812-4 数据中心(最小生成树)
    CCF【小明放学&小明上学】
    TIME_WAIT状态
    ping的详细过程
    两段不相邻子段和之和最大
    神水一题之“Who's in the Middle”
    日进一步之“A Knight's Journey”
  • 原文地址:https://www.cnblogs.com/fu-yun/p/4553689.html
Copyright © 2020-2023  润新知