浅谈WebService的调用

0.前言

    前段时间,公司和电信有个合做,产品对接电信的某个平台,使用了WebService接口的调用,实现了业务受理以及单点登陆。终于使用到了WebService楼主仍是比较兴奋的,目前功能已经上线,下面进行使用总结。WebService涉及到内容仍是比较多的,涉及到发布和调用,有很多知识点,本文只是最简单的调用。
html

1.WebService简介

    WebService是基于soap协议(简单对象访问协议全写为Simple Object Access Protocol)的,全部的webService请求、应答都是创建在soap协议的基础上的,而soap传输数据的载体是xml。WSDL(Web Services Description Language)是WebService的描述语言,它定义了Web Service作什么,怎么作和查询的信息。在验证一个WebService是否好用的时候,咱们一般会选则在浏览器中输入对应的WSDL地址(好比天气预报)。若是显示出一个xml文件,这是好用的,反之就是不可用的。java

    能够这样理解,经过WebService,咱们能够把咱们的程序发布成wsdl接口。在其它平台,经过WSDL生成当前平台可调用的代理类,经过调用生成的接口和方法,实现应用之间的相互调用。   git

   参考:WebService使用的一些总结
web

2.WebService的调用

    调用webservice服务的三种途径,Endpoint ,Disco ,WSDL。客户端在调用电信WebService上行发短信时,是经过 wsdl生成本地代理类方式实行的。而在接收状态报告下行时,能够采用的是 Endpoint方式(客户端不须要生成本地代理类,只须要知道Endpoint地址),好比查看某个城市的天气。apache

    传送门:一些经常使用的WebService
浏览器

    经过wsdl生成代理类:可使用axis2 的wsdl2java  经过命令行生成代理类 (具体可自行百度)    frontend

wsdl2java -p com.generTech.rms.equipment(包名) -d src(目标文件夹位置) -all(生成所有,-client生成客户端,-server生成服务端) -frontend jaxws21  http://192.168.3.80:8080/emp/EmpProvideServiceImp?wsdl(wsdl文件地址)

   或者经过IDE的插件直接生成,好比Intellij IDEA,能够建立WebService项目,自动下载须要的jar包,输入wsdl的url,maven

就直接生成了代理类。ide

    具体方法:New Project——Java——WebService Client测试

    

    自动下载的7个jars 须要下载成功后 才能够根据wsdl生成java code 以及代理类的调用

    

    Tools——WebServices——Generate Wsdl From Java Code

    

建议选中 生成TestCase,能够方便接口测试(调用时须要添加junit的jar)

若是是maven项目,可使用下面的pom

<!--webservice 调用须要的jar -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>

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

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

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

        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.2</version>
        </dependency>

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

        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.4</version>
        </dependency>
        <!--webservice 调用须要的jar -->
    </dependencies>

    测试效果:

   

3.GIT@OSC地址

WebService Maven Project:http://git.oschina.net/lujianing/WebService_Demo

Pom.xml地址:http://git.oschina.net/lujianing/WebService_Demo/blob/master/pom.xml

EndPoint调用(不生成代理类):点这里

相关文章
相关标签/搜索