1、引入依赖

  1. <!-- axis 1.4 jar start -->
  2. <dependency>
  3. <groupId>org.apache.axis</groupId>
  4. <artifactId>axis</artifactId>
  5. <version>1.4</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>commons-discovery</groupId>
  9. <artifactId>commons-discovery</artifactId>
  10. <version>0.2</version>
  11. <exclusions>
  12. <exclusion>
  13. <groupId>commons-logging</groupId>
  14. <artifactId>commons-logging</artifactId>
  15. </exclusion>
  16. </exclusions>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.apache.axis</groupId>
  20. <artifactId>axis-jaxrpc</artifactId>
  21. <version>1.4</version>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.apache.axis</groupId>
  25. <artifactId>axis-saaj</artifactId>
  26. <version>1.4</version>
  27. </dependency>
  28. <dependency>
  29. <groupId>wsdl4j</groupId>
  30. <artifactId>wsdl4j</artifactId>
  31. <version>1.4</version>
  32. </dependency>
  33. <!-- axis 1.4 jar end -->

2、创建客户端

  1. /**
  2. * axis调用webservice服务
  3. *
  4. * @param wsdlURL
  5. * @param methodName
  6. * @param param
  7. * @return
  8. */
  9. public static String callWebServiceAxis(String wsdlURL, String nameSpace, String methodName, String param) {
  10. try {
  11. // 直接引用远程的wsdl文件
  12. Service service = new Service();
  13. Call call = (Call)service.createCall();
  14. call.setTargetEndpointAddress(wsdlURL);
  15. call.setOperationName(new QName(nameSpace, methodName));// 调用的方法名
  16. call.addParameter("name", org.apache.axis.encoding.XMLType.XSD_DATE, javax.xml.rpc.ParameterMode.IN);// 接口的参数
  17. call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
  18. String result = (String)call.invoke(new Object[] {param});// 给方法传递参数,并且调用方法
  19. return result;
  20. } catch (Exception e) {
  21. return e.toString();
  22. }
  23. }

3、测试

  1. public static void main(String[] args) {
  2. String param = "<?xml version=\"1.0\" encoding=\"GBK\"?>\n" + " <FPXT_INPUT>\n" + " <ID>DLSB</ID>\n"
  3. + " <SHMW>NTAwMTAyMjAzMTA5MjM3NjE1Cg==</SHMW>\n"
  4. + " <DATA>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iR0JLIj8+CjxJTlBVVD4gCjxTSD41MDAxMDIyMDMxMDkyMzc2MTU8L1NIPiAgCjxaRkpIPjA8L1pGSkg+IAo8L0lOUFVUPgo=</DATA>\n"
  5. + " </FPXT_INPUT>";
  6. String respXML = callWebServiceAxis("http://www.qdhtxxrd.com:7788/api/plat/xxfp/service/CommService?wsdl",
  7. "http://webservice.xxfp.plat.yshs.aisino.com/", "DLSBService", param);
  8. System.out.println("respXML:" + respXML);
  9. }

image.png