WebService的入门及简单案例

1. WebServices简介
  1.1 什么是WebServices
      WebServices是应用程序组件
      WebServices使用开放协议进行通信
      WebServices是独立并可以自我描述
      WebServices可通过使用UDDI来发现
      WebServices可被其它应用程序使用
      XML是WebServices的基础
  1.2 它如何工作
      XML+HTTP
  1.3 WebServices平台元素
      SOAP(简单对象访问协议)
      UDDI(它是一种目录服务)
      WSDL(Web services描述语言)


2. 为什么使用WebServices
   可在不同的应用程序与平台之间交换数据


3. WebServices开发手段
  3.1 使用jdk开发(1.6及以上版本)
  3.2 使用框架开发,例如:axis2、cxf


4. jdk开发WebServices
  4.1 服务端实现 
    4.1.1 定义一个interfac,使用@WebService注解标注接口,@WebMethod注解标注方法
    4.1.2 定义此接口的实现类,并使用@WebService注解标注
    4.1.3 使用Endpoint(终端)类发布webservice
          String address = "http://localhost:8080/myws";
          Endpoint.publish(address, new MyServiceImpl());
    4.1.4 测试服务
      4.1.4.1 直接在浏览器中输入:
              http://localhost:8080/myws?wsdl
      4.1.4.2 使用Eclipse自带的工具进行测试
              Launch the Web Services Explorer-->WSDL Page  

      注1:WSDL是什么?WSDL全名为:网络服务描述语言,它是Web Service的描述语言,它包含一系列描述某个web service的定义        
 

  4.2 客户端实现
    4.2.1 使用jdk的wsimport.exe(java_home\bin)工具生成客户端代码
          shift+右键
          wsimport -keep url?wsdl
          wsimport -keep *.xml

    4.2.2 调用客户端代码完成
          // 创建工厂对象
      WebServiceImplService factory = new WebServiceImplService();
      // 通过工厂对象创建WebServiceImpl对象
      WebServiceImpl webServiceImpl = factory.getWebServiceImplPort();


//阿里云市场
//webservice相关网站:webxml
5. 案例:电话号码归属地查询
   MobileCodeWS mobileCodeWS = new MobileCodeWS(); 
   MobileCodeWSSoap mobileCodeWSSoap = mobileCodeWS.getMobileCodeWSSoap(); 


1. Axis2的版本是1.7.6
   Binary distribution     axis2-1.7.6-bin.zip(可执行版)
   WAR distribution     axis2-1.7.6-war.zip(放在tomcat下可发布的war包版)

2. eclipse的插件
   Service Archive plugin for Eclipse    axis2-eclipse-service-plugin-1.7.6.zip(用来将服务代码打包成后缀名为.aar文件的插件)
   Code Generator plugin for Eclipse    axis2-eclipse-codegen-plugin-1.7.6.zip(用来将服务代码生成wsdl文件以及解析将wsdl文件生成客户端代码的插件)

 

 

在通过cmd生成文件后写的一个号码归属地实例

package com.company.test;

import cn.com.webxml.MobileCodeWS;
import cn.com.webxml.MobileCodeWSSoap;

public class Test {
    public static void main(String[] args) {
        MobileCodeWS mobileCodeWS = new MobileCodeWS();
        MobileCodeWSSoap mobileCodeWSSoap = mobileCodeWS.getMobileCodeWSSoap();
        String mobileCodeInfo = mobileCodeWSSoap.getMobileCodeInfo("13999999999", null);
        System.out.println(mobileCodeInfo);
    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值