zoukankan      html  css  js  c++  java
  • 5.开发webservice

    package com.atguigu.ws;
    
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    
    /**
     * 
     * @author Administrator
     *
     */
    @WebService
    public interface HelloWS {
        
        @WebMethod
        public String sayHello(String name);
    }
    package com.atguigu.ws.impl;
    
    import javax.jws.WebService;
    
    import com.atguigu.ws.HelloWS;
    
    @WebService
    public class HelloWSImpl implements HelloWS {
    
        @Override
        public String sayHello(String name) {
            System.out.println("server sayHello() "+name);
            
            return "Hello "+name;
        }
        
    }
    package com.atguigu.server;
    
    import javax.xml.ws.Endpoint;
    
    import com.atguigu.ws.impl.HelloWSImpl;
    
    /**
     * 发布webservice
     * @author Administrator
     *
     */
    public class ServerTest {
    
        public static void main(String[] args) {
            String address = "http://192.168.0.114:8989/day01_ws/hellows";
            //Endpoint发布
            Endpoint.publish(address, new HelloWSImpl());
            System.out.println("发布webservice成功");
        }
    }

     

    1).打开cmd工具窗口,进入客户端src目录(可拖拽进入)执行wsimport -keep url命令,进入eclipse刷新客户端src目录

    package com.atguigu.ws.client.test;
    
    import com.atguigu.ws.impl.HelloWSImpl;
    import com.atguigu.ws.impl.HelloWSImplService;
    
    /**
     * 调用webservice
     * @author Administrator
     *
     */
    public class ClientTest {
    
        public static void main(String[] args) {
            /*
             * 产生代理对象
             */
            HelloWSImplService factory = new HelloWSImplService();
            HelloWSImpl helloWS = factory.getHelloWSImplPort();
            System.out.println(helloWS);
        
            String result = helloWS.sayHello("Jack");
            System.out.println(result);
        }
    }

    测试结果:

    客户端:

    服务器端:

  • 相关阅读:
    虚拟设备 ide1:0 将开始断开
    虚拟机集群启动 某一台启动失败
    jeesite1,工具类,文件介绍
    line-clamp
    js中同名的函数的调用情况
    获取子页面iframe的点击事件及iframe跨域的交互
    Docker环境搭建入门
    软件工程课后作业:论我对百度搜索的看法
    第二阶段第十天12.10
    软件工程:用户场景描述
  • 原文地址:https://www.cnblogs.com/tingbogiu/p/6041726.html
Copyright © 2011-2022 走看看