博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
webService-cxf
阅读量:2204 次
发布时间:2019-05-03

本文共 1576 字,大约阅读时间需要 5 分钟。

官网必备包,自己研究api:

 

然后就是一个简单的例子了:

  先服务端:

    

package com.cxf;import javax.jws.WebParam;import javax.jws.WebService;@WebServicepublic interface IHelloWorld {    public String sayHi(@WebParam(name="text")String text);}
package com.cxf;import javax.jws.WebParam;import javax.jws.WebService;@WebServicepublic class HelloWorld implements IHelloWorld {    public String sayHi(@WebParam(name="text") String text){        return "sayHi:"+text;    }}
package com.cxf;import javax.xml.ws.Endpoint;public class ServerSimple {    public ServerSimple() throws Exception{        System.out.println("starting Server");        HelloWorld h=new HelloWorld();        String address="http://localhost:9000/helloWorld";        Endpoint.publish(address, h);    }    public static void main(String[] args) throws Exception{        new ServerSimple();        System.out.println("server ready...");        Thread.sleep(60*1000);        System.exit(0);    }}

 

然后客户端:

 

package com.cxf;import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;public final class Client {    private Client(){}    public static void main(String[] args) {        JaxWsProxyFactoryBean factory=new JaxWsProxyFactoryBean();        factory.setServiceClass(IHelloWorld.class);        factory.setAddress("http://localhost:9000/helloWorld");        IHelloWorld client=(IHelloWorld)factory.create();        System.out.println("Invoke sayHi()....");        System.out.println(client.sayHi(System.getProperty("user.name")));        System.exit(0);    }}

 

  至于关于什么是webservice什么的,请参考

  共同进步,共同学习

 

 

转载于:https://www.cnblogs.com/huzi007/p/3739082.html

你可能感兴趣的文章
阿里云《云原生》公开课笔记 第一章 云原生启蒙
查看>>
阿里云《云原生》公开课笔记 第二章 容器基本概念
查看>>
阿里云《云原生》公开课笔记 第三章 kubernetes核心概念
查看>>
阿里云《云原生》公开课笔记 第四章 理解Pod和容器设计模式
查看>>
阿里云《云原生》公开课笔记 第五章 应用编排与管理
查看>>
阿里云《云原生》公开课笔记 第六章 应用编排与管理:Deployment
查看>>
阿里云《云原生》公开课笔记 第七章 应用编排与管理:Job和DaemonSet
查看>>
阿里云《云原生》公开课笔记 第八章 应用配置管理
查看>>
阿里云《云原生》公开课笔记 第九章 应用存储和持久化数据卷:核心知识
查看>>
linux系统 阿里云源
查看>>
国内外helm源记录
查看>>
牛客网题目1:最大数
查看>>
散落人间知识点记录one
查看>>
Leetcode C++ 随手刷 547.朋友圈
查看>>
手抄笔记:深入理解linux内核-1
查看>>
内存堆与栈
查看>>
Leetcode C++《每日一题》20200621 124.二叉树的最大路径和
查看>>
Leetcode C++《每日一题》20200622 面试题 16.18. 模式匹配
查看>>
Leetcode C++《每日一题》20200625 139. 单词拆分
查看>>
Leetcode C++《每日一题》20200626 338. 比特位计数
查看>>