少林

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

//服务端发布

package com.ws.server.test;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class MyEndPointer {
    public static void main(String[] args) {
        publish();
    }
  
    private static void publish() {
        Endpoint.publish("http://127.0.0.1:8989/mywebservice", new MyImpl());
        
    }
}
@WebService
public class MyImpl {
    @WebMethod
    public String sayHello(String name) {
        System.out.println("WS server: " + name);
        return "Hi " + name;
    }
}
//客户端调用,先用wsimport -keep [wsdl地址] 生成客户端代码
public class ClientTest {
    public static void main(String[] args) {
        test();
    }

    private static void test() {
        try {
            MyImplService implService = new MyImplService();
            MyImpl myImplPort = implService.getMyImplPort();
            String sayHello = myImplPort.sayHello("少林");
            System.out.println(sayHello);
        } catch (WebServiceException e) {
            System.out.println("连接失败");
        }
        
    }
}

 

部分截图如下:

 

posted on 2015-10-06 14:36  Stanley_yu  阅读(842)  评论(0编辑  收藏  举报