zoukankan      html  css  js  c++  java
  • webService服务简单实现

    首先写一个简单的webservice服务

    package com.service.impl;
    
    import java.util.Date;
    
    import javax.jws.WebService;
    
    import com.service.HelloWorld;
    
    
    @WebService
    public class HelloWorlds implements HelloWorld{
    
        @Override
        public String sayHi(String name) {
            // TODO Auto-generated method stub
             return name+"您好!现在时间是:"+new Date();  
        }
    }

    接下来就是将weibservice服务发布暴露出来

    package com.action;
    
    import javax.xml.ws.Endpoint;
    
    import com.service.HelloWorld;
    import com.service.impl.HelloWorlds;
    
    public class ServiceMain {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            HelloWorld hw = new HelloWorlds();  
            //调用Endpoint的publish方法发布Web Service  
            Endpoint.publish("http://127.0.0.1/helloWorld", hw);  
            System.out.println("Web Service暴露成功!");  
        }
    
    }

    通过访问http://127.0.0.1/helloWorld?wsdl就可以看到服务的描述,也就是webservice三大组件中的wsdl.

    接下来就是创建webservice服务的客户端用来调用服务,记住在创建的时候在WSDL URL输入上面查看描述服务的地址就可以自动生成对应的webservice客户端

    我的生成的文件如下

    最后就是写测试程序开始调用webservice发布的服务了

    package com.action;
    
    
    
    import com.service.impl.HelloWorlds;
    import com.service.impl.HelloWorldsService;
    public class WebService {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub        
            HelloWorldsService service=new HelloWorldsService();
            HelloWorlds action=service.getHelloWorldsPort();
            String message=action.sayHi("JIM");
            System.out.println("调webservice:"+message); 
        }
    
    }
  • 相关阅读:
    webpack2 前篇
    vue 的调试工具
    CSS 命名规范总结
    reset.css
    推荐几个精致的web UI框架
    自己是个菜鸟 自己查找的简单的适合初学的Makefile
    Linux下编译、使用静态库和动态库 自己测过的
    函数参数的传递 动态内存传递问题(指针的指针)
    二级指针 (C语言)
    find_if查找vector内对象的成员 作为菜鸟一直不会用也不敢用
  • 原文地址:https://www.cnblogs.com/feitianshaoxai/p/6865829.html
Copyright © 2011-2022 走看看