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"));
        }
    }
  • 相关阅读:
    HDU 5363 Key Set(快速幂取模)
    HDU 5339 Untitled(暴搜)
    POJ 2406 Power Strings
    Dedecms备份还原网站有效方法
    DEDECMS文章列表每隔8行文章添加分隔虚线
    DEDECMS突破TAG和关键字长度的限制
    为织梦dedecms制作全文RSS订阅源
    DedeCms中Channel用typeid无效
    织梦CMS/Dedecms添加自定义函数
    sql批量换dedecms文章来源和作者
  • 原文地址:https://www.cnblogs.com/rocky-fang/p/5436614.html
Copyright © 2011-2022 走看看