• 利用jdk的wsimport.exe生成WebServices客户端代码


    
    
    //服务端发布

    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("连接失败");
            }
            
        }
    }

    部分截图如下:

  • 相关阅读:
    Java循环结构
    Java正则表达式
    Java日期时间
    Java如何输入数据
    Java数组
    Java StringBuffer和StringBuilder类
    Java String类
    Java Character类
    Java Number&Math类
    python之二维码生成
  • 原文地址:https://www.cnblogs.com/yushouling/p/4857112.html
Copyright © 2020-2023  润新知