首页 > 技术文章 > webservice入门

sjzxs 2018-08-07 20:33 原文

 简单来说就是一个系统调用另一个系统,就叫远程调用。

  webservice原理:  

webservice定义:                                            

 

webservice一种使用http传输SOAP协议数据的远程调用技术

 

  WSDL作用:

web服务描述语言(web service discription language

 

webservice服务端的使用说明书

 

  SOAP作用

简单对象访问协议(simple object access protocol

 

约束XML标签

 

  UDDI作用

 

          提供webservice服务端的搜索和注册功能

  通过简单的了解后写一个入门测试案例:

      第一步:创建服务类

        类上加@Webservice注解

package cn.itcast;

import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class MyService {
    public String sayHello(String name,Integer age){
        System.out.println("这是服务端");
        return "hello"+name;
    }
    public static void main(String[] args) {
    Endpoint.publish("http://localhost:12356/hello", new MyService());
    System.out.println("服务发布成功");
    }

}

       第二步:测试服务是否发布成功

阅读WSDL使用说明书,确定接口、类、方法、参数和返回值都存在,说明发布成功

 

WSDL地址规则:服务地址+?wsdl

http://localhost:12356/hello?wsdl 如图所示:

  

     第三步:客户端入门程序:① 1.1.1 使用wsimport命令解析WSDL,进入cmd生成本地代码(生成位置+wsdl2java -d . 说明书)(D:\JAVA框架\workspace\bos_parent\bos_web\src\main\java\cn\itcast\bos\web\action>wsdl2java -d . http://localhost:12356/hello?wsdl)

    

    成功界面:

    

    使用客户端访问服务端:

          
public class Mytest {
    public static void main(String[] args) {
    MyServiceService myServiceService = new MyServiceService();
    MyService mt = myServiceService.getMyServicePort();
    String sayHello = mt.sayHello("小明", 123);
    System.out.println(sayHello);
    }
}

      

 

  

 

    

 

 

 

 

推荐阅读