一个简单的webservice客户端demo

首先我们是客户端,我们要找一个服务端来配合我们调试,可以在这个网址里找个你喜欢的免费服务WEB服务(Web Servicrs)| 免费WEB服务 | 商业WEB服务 | XML Web Servicrs - WEBXML

比如下面这个查手机号归属地的:

 我们新建一个maven工程,在pom文件里引用axis依赖(可以在此连接Apache 轴对axis进行了解)。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.yulong.wsdltest</groupId>
    <artifactId>wsdltest</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <fastjson.version>1.2.83</fastjson.version>
    </properties>

    <dependencies>
        
        <!--wsdl-->
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>com.sixdimensions.commons.osgi.wrapper</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>

        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>apache-log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.8</version>
        </dependency>

        <dependency>
            <groupId>org.lucee</groupId>
            <artifactId>saaj</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-wsdl4j</artifactId>
            <version>1.5.1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.2</version>
        </dependency>

    </dependencies>

</project>

然后我们创建一个client。

 

 填入刚刚的wsdl url(http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl)。

 然后就生成了相应的类。

我们再写个测试类调用一下看看。

public static <MobileCodeWSSoap> void main(String[] argv) throws ServiceException, RemoteException {
    MobileCodeWS service = new MobileCodeWSLocator();
    MobileCodeWSSoap_PortType port = service.getMobileCodeWSSoap();
    String body = port.getMobileCodeInfo("15715700000",null);
    System.out.println(body);
  }

发现完美运行:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值