CXF 发布 Web Service

简介:

使用CXF框架开发

①.CXF : xfire–>xfire + celtrix
做web service开发的开源框架

②.开发Server端:
加入cxf的Jar包即可,其它不需要动

测试CXF支持的数据类型
1.基本类型
–int,float,boolean等
2.引用类型
–String
–集合:数组,List, Set, Map
–自定义类型 Student




@WebService
public class DataTypesImpl implements DataTypeWS {  //SEI接口实现类

    public boolean addStudent(Student s) {
        System.out.println("server addStudent()" +s);
        return true;
    }

    public Student getStudentById(int id) {
        System.out.println("server  getStudentById()" +id);
        return new Student(id,"CAT",1000);
    }

    public List<Student> getStudentByPrice(float price) {
        System.out.println("server  getStudentByPrice()" +price);
        List<Student> list=new ArrayList<Student>();
        list.add(new Student(1,"tg1",price+1));
        list.add(new Student(2,"tg2",price+2));
        list.add(new Student(3,"tg3",price+3));
        return list;
        
        
    }

    public Map<Integer, Student> getAllStudentMap() {
        System.out.println("server getAllStudentMap()" );
        Map<Integer,Student> map=new HashMap<Integer, Student>();
        map.put(1,new Student(1,"TG1",123));
        map.put(2,new Student(2,"TG2",143));
        map.put(3,new Student(3,"TG3",153));
        
        return map;
    }


public class serviceTest2 {  //发布服务

    /**
     * @param args
     */
    public static void main(String[] args) {
        //客户端发送web service请求的url
        String address="http://127.0.0.1:8888/tg_ws_cxf/datatypews";
        //处理请求的SEI对象
        DataTypeWS dataTypesImpl=new DataTypesImpl();
        //发布web service
        //Endpoint.publish("http://127.0.0.1/person_ws/HelloWS", hellows);
    Endpoint.publish(address, dataTypesImpl);
    
        
        
        System.out.println("web service 发布成功");

    }

--------------------------------------------------------------------------

(中间必须先生成客户端代码   打开cmd .. 见我的上一篇博客http://blog.csdn.net/tanggao1314/article/details/48393205    图2


public class ClientTest {   //客户端测试

    /**
     * @param args
     */
    public static void main(String[] args) {
        DataTypesImplService factory=new DataTypesImplService();
        DataTypeWS dataTypeWS=factory.getDataTypesImplPort();
        
        boolean s=dataTypeWS.addStudent(new Student());
        System.out.println(s);
        
        List<Student> list=dataTypeWS.getStudentByPrice(12);
        System.out.println(list);
        
        Return r=dataTypeWS.getAllStudentMap();
        
        List<com.tg.web.service.GetAllStudentMapResponse.Return.Entry> entrys=r.getEntry();
        
        for(com.tg.web.service.GetAllStudentMapResponse.Return.Entry entry:entrys){
            Integer id=entry.getKey();
            Student student=entry.getValue();
            System.out.println(id+"-"+student);
        }
        
        

    }

目录
相关文章
|
2月前
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
|
2月前
|
关系型数据库 MySQL Linux
【Azure 应用服务】在创建Web App Service的时候,选Linux系统后无法使用Mysql in App
【Azure 应用服务】在创建Web App Service的时候,选Linux系统后无法使用Mysql in App
【Azure 应用服务】在创建Web App Service的时候,选Linux系统后无法使用Mysql in App
|
2月前
|
Shell PHP Windows
【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Windows directory.
【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Windows directory.
|
2月前
|
Linux 应用服务中间件 网络安全
【Azure 应用服务】查看App Service for Linux上部署PHP 7.4 和 8.0时,所使用的WEB服务器是什么?
【Azure 应用服务】查看App Service for Linux上部署PHP 7.4 和 8.0时,所使用的WEB服务器是什么?
|
2月前
【Azure 应用服务】通过 Web.config 开启 dotnet 应用的 stdoutLog 日志,查看App Service 产生500错误的原因
【Azure 应用服务】通过 Web.config 开启 dotnet 应用的 stdoutLog 日志,查看App Service 产生500错误的原因
|
2月前
|
Linux Python
【Azure 应用服务】Azure App Service For Linux 上实现 Python Flask Web Socket 项目 Http/Https
【Azure 应用服务】Azure App Service For Linux 上实现 Python Flask Web Socket 项目 Http/Https
|
2月前
|
存储 安全 网络安全
【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?
【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?
|
2月前
|
存储 Linux 网络安全
【Azure 应用服务】App Service For Linux 如何在 Web 应用实例上住抓取网络日志
【Azure 应用服务】App Service For Linux 如何在 Web 应用实例上住抓取网络日志
|
2月前
【Azure 云服务】Azure Cloud Service 为 Web Role(IIS Host)增加自定义字段 (把HTTP Request Header中的User-Agent字段增加到IIS输出日志中)
【Azure 云服务】Azure Cloud Service 为 Web Role(IIS Host)增加自定义字段 (把HTTP Request Header中的User-Agent字段增加到IIS输出日志中)
|
2月前
|
Web App开发 安全 JavaScript
【Azure 应用服务】App Service 通过配置web.config来添加请求返回的响应头(Response Header)
【Azure 应用服务】App Service 通过配置web.config来添加请求返回的响应头(Response Header)