axis2調用WSDL接口


public static JSONObject sendWsdl(String url,String xmlStr){
        JSONObject res=new JSONObject();
        try {
            String endpoint = url.replace("?wsdl","");//不需要傳?wsdl
            //直接引用遠程的wsdl文件
            Options options = new Options();
            options.setTo(new EndpointReference(endpoint));
            ServiceClient sender = new ServiceClient();
            sender.setOptions(options);

            OMFactory fac = OMAbstractFactory.getOMFactory();
            OMNamespace omNs = fac.createOMNamespace("http://localhost/services/IRService","");//參數1(uri)=即為wsdl文檔的targetNamespace;參數2(prefix)=可不填
            OMElement method = fac.createOMElement("createAuto",omNs);//方法名
            OMElement in0 = fac.createOMElement("in0", omNs);//方法參數
            in0.setText(xmlStr);//參數值
            method.addChild(in0);//添加參數

            OMElement resultEle = sender.sendReceive(method);//調用wsdl
            System.out.println("調用接口結果:"+resultEle.toString());
}

加入maven依賴:

<!--axis2 begin -->
<dependency>
   <groupId>org.apache.axis2</groupId>
   <artifactId>axis2-spring</artifactId>
   <version>1.7.8</version>
   <exclusions>
      <exclusion>
         <groupId>javax.servlet</groupId>
         <artifactId>servlet-api</artifactId>
      </exclusion>
   </exclusions>
</dependency>
<dependency>
   <groupId>org.apache.axis2</groupId>
   <artifactId>axis2-transport-http</artifactId>
   <version>1.7.8</version>
   <exclusions>
      <exclusion>
         <groupId>javax.servlet</groupId>
         <artifactId>servlet-api</artifactId>
      </exclusion>
   </exclusions>
</dependency>
<dependency>
   <groupId>org.apache.axis2</groupId>
   <artifactId>axis2-transport-local</artifactId>
   <version>1.7.8</version>
   <exclusions>
      <exclusion>
         <groupId>javax.servlet</groupId>
         <artifactId>servlet-api</artifactId>
      </exclusion>
   </exclusions>
</dependency>
<dependency>
   <groupId>org.apache.axis2</groupId>
   <artifactId>axis2-xmlbeans</artifactId>
   <version>1.7.8</version>
   <exclusions>
      <exclusion>
         <groupId>javax.servlet</groupId>
         <artifactId>servlet-api</artifactId>
      </exclusion>
   </exclusions>
</dependency>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM