webService-cxf

官网必备包,自己研究api:http://cxf.apache.org/download.html

 

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

  先服务端:

    

复制代码
package com.cxf;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface IHelloWorld {

    public String sayHi(@WebParam(name="text")String text);
}
复制代码
复制代码
package com.cxf;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public 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什么的,请参考http://www.w3school.com.cn/ws.asp

  共同进步,共同学习

 

 

posted @   全力以赴001  阅读(314)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
历史上的今天:
2013-05-20 UML中的部署图
2013-05-20 UML中的构件图
2013-05-20 UML模型
点击右上角即可分享
微信分享提示