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>