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

0.jar包

        <dependency>
                <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxrpc</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.soap</groupId>
            <artifactId>javax.xml.soap-api</artifactId>
            <version>1.4.0</version>
        </dependency>

        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.2</version>
<!--            <exclusions>-->
<!--                <exclusion>-->
<!--                    <groupId>commons-logging</groupId>-->
<!--                    <artifactId>commons-logging</artifactId>-->
<!--                </exclusion>-->
<!--            </exclusions>-->
        </dependency>


<!--        <dependency>-->
<!--            <groupId>commons-logging</groupId>-->
<!--            <artifactId>commons-logging</artifactId>-->
<!--            <version>1.2</version>-->
<!--        </dependency>-->

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

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

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

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

几点说明:

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

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

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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值