WebService的实现

1.WebService是什么?
WebService是一种跨编程语言和跨操作系统平台的远程调用技术。
2.其中要知道的几个概念:
WSDL、SOAP、CXP、SEI;
3.如果WSDL可以访问,则代表服务器端可用。
4.开发的大体思路:
1.Server:@WebService
@WebMethod
发布WebService:用Endpoint.publish(… , …);
2.Client:路径?wsdl
WebService浏览器
5.具体实现:
1)SEI(Interface)--------------->SEI的实现(.class)[—要加@WebService, @WebMethod-----]
代码实现接口:
package com.atguigu.day01_ws.ws;
public interface HelloWS {

}
代码实现继承类:
package com.atguigu.day01_ws.ws;
import javax.jws.WebService;
/*

  • SEI的实现
    */
    @WebService
    public class HelloWSImpl implements HelloWS {

    public String sayHello(String name) {
    System.out.println(“server sayHello()”+name);
    return "Hello "+name;
    }

}

2) ServerTest.java-------------->发布:Endpoint.publish(address,implement);
注意:address可以随便取,而implement是对类进行实例化的对象
代码实现:package com.atguigu.day01_ws.ws.server;

import javax.xml.ws.Endpoint;
import com.atguigu.day01_ws.ws.HelloWSImpl;
/*

  • 发布Web Service
    */
    public class ServerTest {
    public static void main(String[]args) {
    String address=“http://localhost:8989/day01_ws/hellows”;
    Endpoint.publish(address, new HelloWSImpl());
    System.out.println(“发布webservice成功!”);
    }
    }

    3)ClientTest.java------------->客户端测试发布:建立一个实现服务的工厂
    HelloWSImplService factory=new HelloWSImplService();
    HelloWSImpl helloWS=factory.getHelloWSImplPort();
    代码实现:
    package com.atguigu.day01_ws_client.test;
    import com.atguigu.day01_ws.ws.HelloWSImpl;
    import com.atguigu.day01_ws.ws.HelloWSImplService;
    /*

  • 调用web service
    */
    public class ClientTest {

    public static void main(String[]args) {
    HelloWSImplService factory=new HelloWSImplService();
    HelloWSImpl helloWS=factory.getHelloWSImplPort();
    System.out.println(helloWS.getClass());

     String result=helloWS.sayHello("Jack");
     System.out.println("client "+result);
    

    }
    }

6.生成wsdl:
1)直接生成:cmd------> cd 到生成目录下+wsimport -keep …?wsdl
2)在本地生成:打开TCP/IP Monitor(进行监听)------->建立一个wsdl文件-------->
cd 到生成目录下+wsimport -keep …?wsdl(这个wsdl文件的路径)
7.通过CXF来实现WebService
在project里新建一个文件夹lib,加入cxf的.jar包。在cmd:cd 到生成目录下+wsdl2java+…?wsdl

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值