WebService

来源:互联网 发布:linux uniq命令详解 编辑:程序博客网 时间:2024/06/06 02:40

1.创建 web service project 项目 service服务端

package com.hyan.service;import javax.jws.WebService;import javax.xml.ws.Endpoint;//必须加入该注解@WebServicepublic class ServiceHello {    /**     * @param args     */    public String getValue(String key){        return key+" success";    }    public static void main(String[] args) {        // TODO Auto-generated method stub        //终端发布         Endpoint.publish("http://localhost:8888/service/ServiceHello", new ServiceHello());        System.out.println("ws publish success");    }}

2.使用 wsimport 编译 wsdl 到client 项目

wsimport -s 编译到的目录
-p 编译到的包
-keep ws的 url或文件

3.调用

package com.ws.client.test;import com.ws.client.ServiceHello;import com.ws.client.ServiceHelloService;public class TestWs {    /**     * @param args     */    public static void main(String[] args) {        // TODO Auto-generated method stub        ServiceHello sh = new ServiceHelloService().getServiceHelloPort();        String value = sh.getValue("123");        System.out.println("from ws value"+value);    }}
0 0
原创粉丝点击