zoukankan      html  css  js  c++  java
  • WebService

    服务端:

    1. webservice类

    import javax.jws.WebService;
    
    import javax.jws.WebService;

    @WebService
    public class HelloWS {

        public String getWhether(String city){
            if(city.equals("beijing")){
                return "bad";
            }else{
                return "good";
            }
        }
    }

    2. 测试类

    import javax.xml.ws.Endpoint;

    public class TestClass {

        public static void main(String[] args) {
            Endpoint.publish("http://localhost:12345/helloWS", new HelloWS());
        }
    }

    3. 服务端测试访问

     客户端:

    4. 客户端测试访问方式一:

    import test_webservice.HelloWS;
    import test_webservice.HelloWSService;
    public class ClientTest {
    
        public static void main(String[] args) {
    
            HelloWSService hwss = new HelloWSService();
            HelloWS helloWSPort = hwss.getHelloWSPort();
            System.out.println(helloWSPort.getWhether("beijing"));
            System.out.println(helloWSPort.getWhether("tianjin"));
        }
    }

    5. 客户端测试访问方式二

    import test_webservice.HelloWS;
    
    public class TestClient2 {
    
        public static void main(String[] args) throws MalformedURLException {
            //上哪去找
            URL url = new URL("http://localhost:12345/helloWS"); 
            //找什么
            QName qname = new QName("http://test_webservice/", "HelloWSService");
            //查找视图
            Service service = Service.create(url, qname);
            //得到接口
            HelloWS ws = service.getPort(HelloWS.class);
            System.out.println(ws.getWhether("beijing"));
            System.out.println(ws.getWhether("tianjin"));
        }
    }
  • 相关阅读:
    聊聊MySQL的索引吧
    污力满满的技术解读,瞬间印象深刻
    lua语言(1):安装、基本结构、函数、输入输出
    pandas中的那些让人有点懵逼的异常(坑向)
    与分布式相关的面试题
    图解IP基础知识
    Date类
    String 与StringBuffer习题
    Java的常用类 String
    线程练习题
  • 原文地址:https://www.cnblogs.com/rocky-fang/p/5436614.html
Copyright © 2011-2022 走看看