• 部署基于JDK的webservice服务类


    部署服务端

    两个注解(@WebService @WebMethod)、一个类(Endpoint)

    首先新建JAVA工程ws-server

    目录结构如下

    在工程里新建一个接口,申明一个方法。

    package com.atguigu.day01_ws.ws;
    
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    
    /*
     * SEI: 
     */
    @WebService
    public interface HelloWS {
    
        @WebMethod
        public String sayHello(String name);
    }

    在新建一个实现类,实现接口中的方法。

    package com.atguigu.day01_ws.ws;
    
    import javax.jws.WebService;
    
    /*
     * SEI��ʵ��
     */
    @WebService
    public class HelloWSImpl implements HelloWS {
    
        @Override
        public String sayHello(String name) {
            System.out.println("server sayHello()"+name);
            return "Hello " +name;
        }
    
    }

    再发布部署实现类

    package com.atguigu.day01_ws.ws.server;
    
    import javax.xml.ws.Endpoint;
    
    import com.atguigu.day01_ws.ws.HelloWSImpl;
    
    /*
     * 发布Web Service
     */
    public class ServerTest {
    
        public static void main(String[] args) {
    
            //String address = "http://192.168.10.165:8989/day01_ws/hellows";
            String address = "http://192.168.107.214:8989/day01_ws/hellows";
            Endpoint.publish(address , new HelloWSImpl());
            System.out.println("发布webservice成功!");
        }
    }

    提示发布成功后,那就浏览器访问http://192.168.107.214:8989/day01_ws/hellows?wsdl
    如果出现 wsdl文档页面 ,说明发布成功

    生成客户端(借助jdkwsimort.exe工具生成客户端代码)

    新建JAVA工程 ws-client

    用cd命令切换到ws-client工程实际目录下的src目录下 调用命令 wsimport -keep http://192.168.107.214:8989/day01_ws/hellows?wsdl

    会在src目录下生成相应的客户端代码

    目录结构图如下

    最终在当前工程下,新建Test类,

    package com.sinosoft.webservice.reFundCallBack;
    
    import java.rmi.RemoteException;
    
    public class Test {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            HelloWSPortTypeProxy proxy=new HelloWSPortTypeProxy();  
             try {
                System.out.println(proxy.sayHello("大兵哥"));
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }  
             //System.out.println(proxy.getPrice());  
             //proxy.printInfo();  
             //proxy.setName("大兵哥");  
    
    
        }
    
    }


    最终控制台 输出 Hello 大兵哥

  • 相关阅读:
    练习5
    图例设置了却不显示
    easyui中多级表头,主表头不能添加field字段,否则不居中
    springboot热部署
    ReactDom.render调用后没有渲染
    webpack打包配置模板
    overridePendingTransition
    multiDex分包时指定主dex的class列表
    android实现手势锁
    动态补丁构建工具nuwa中的“坑”
  • 原文地址:https://www.cnblogs.com/vinplezhang/p/4041018.html
Copyright © 2020-2023  润新知