使用idea通过wsdl完成访问WebService接口客户端代码

朱雀 2022-11-22 13:00 729阅读 0赞

0.jar包

  1. <dependency>
  2. <groupId>wsdl4j</groupId>
  3. <artifactId>wsdl4j</artifactId>
  4. <version>1.4</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.apache.axis</groupId>
  8. <artifactId>axis</artifactId>
  9. <version>1.4</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>javax.xml</groupId>
  13. <artifactId>jaxrpc</artifactId>
  14. <version>1.1</version>
  15. </dependency>
  16. <dependency>
  17. <groupId>javax.xml.soap</groupId>
  18. <artifactId>javax.xml.soap-api</artifactId>
  19. <version>1.4.0</version>
  20. </dependency>
  21. <dependency>
  22. <groupId>commons-discovery</groupId>
  23. <artifactId>commons-discovery</artifactId>
  24. <version>0.2</version>
  25. <!-- <exclusions>-->
  26. <!-- <exclusion>-->
  27. <!-- <groupId>commons-logging</groupId>-->
  28. <!-- <artifactId>commons-logging</artifactId>-->
  29. <!-- </exclusion>-->
  30. <!-- </exclusions>-->
  31. </dependency>
  32. <!-- <dependency>-->
  33. <!-- <groupId>commons-logging</groupId>-->
  34. <!-- <artifactId>commons-logging</artifactId>-->
  35. <!-- <version>1.2</version>-->
  36. <!-- </dependency>-->

注意:由于包commons-discovery与包commons-logging冲突,所以注释掉Spring中用到的commons-logging

1.打开idea的全局搜索(默认是双击shift键)

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXFpYW5nOTE1_size_16_color_FFFFFF_t_70

20201104170435419.png

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXFpYW5nOTE1_size_16_color_FFFFFF_t_70 1

20201104171403578.png

获取接口实例及调用方法的代码如下:

  1. JDKJService service = new JDKJServiceLocator();
  2. JDKJServiceSoapBindingStub webService = (JDKJServiceSoapBindingStub) service.getServiceSoap();

几点说明:

1.接口的调用可以写个工具类,之后再调用时直接获取即可。

2.webService服务的地址在以Locator结尾的类中,如果需要动态获取此地址而不是写死在代码中,可以给规定此地址的变量价格set方法,之后在实例化完成时给此变量重新赋值。示例如下:

  1. ItemDO itemDO = "比如数据库获取地址值";
  2. JDKJServiceLocator service = new JDKJServiceLocator();
  3. service.setServiceSoap_address(address);
  4. service.setServiceSoap12_address(address);
  5. JDKJServiceSoapBindingStub webService = (JDKJServiceSoapBindingStub) service.getServiceSoap();

发表评论

表情:
评论列表 (有 0 条评论,729人围观)

还没有评论,来说两句吧...

相关阅读