• 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); 
        }
    
    }
  • 相关阅读:
    Python作业本——第4章 列表
    Python作业本——第3章 函数
    Python作业本——前言
    Yandex企业邮箱申请教程
    如何看待HTTP/3
    图床合集
    Windows File Recovery
    在线检测你的密码是否被泄露
    mybatis的mapper文件内容回顾
    java中系统中的常量
  • 原文地址:https://www.cnblogs.com/feitianshaoxai/p/6865829.html
Copyright © 2020-2023  润新知