码迷,mamicode.com
首页 > 其他好文 > 详细

cxf和jaxws的对比

时间:2016-07-11 18:42:51      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

和jaxws相比,服务器发布方式和客户端访问方式不同

服务器发布方式:

package service;

import javax.xml.ws.Endpoint;

import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

/**
 * 发布服务
 */
public class FaBu {

    public static void main(String[] args) {
        //发布soap协议的
        JaxWsServerFactoryBean jaxWsServerFactoryBean = new JaxWsServerFactoryBean();
        //指定webservice地址
        jaxWsServerFactoryBean.setAddress("http://127.0.0.1:12345/weather");
        //指定portType
        jaxWsServerFactoryBean.setServiceClass(WeatherInterface.class);
        //指定服务类对象
        jaxWsServerFactoryBean.setServiceBean(new Impl());
        //发布服务
        jaxWsServerFactoryBean.create();
        
    }
}

客户端访问:

package client;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import http.pojo.Pojo;
import http.pojo.PojoPortType;
import http.pojo.PojoService;

import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;


/**
 * 使用cxf的方法
 * 
 */
public class Cxf_client1 {

    public static void main(String[] args) {
                //发布soap协议的
             JaxWsProxyFactoryBean jaxWsServerFactoryBean = new JaxWsProxyFactoryBean();
                //调用webservice地址
                jaxWsServerFactoryBean.setAddress("http://127.0.0.1:12345/weather");
                //设置portType
                jaxWsServerFactoryBean.setServiceClass(PojoPortType.class);
                //创建portType
                PojoPortType pojoPortType = (PojoPortType) jaxWsServerFactoryBean.create();
                List<Pojo> queryWeather = pojoPortType.queryWeather("郑州");
                //解析
                for (Pojo pojo : queryWeather) {
                    System.out.println(pojo.getDetail());
                    Date date = pojo.getDate().toGregorianCalendar().getTime();
                    System.out.println(new SimpleDateFormat("yyMMdd").format(date));
                    System.out.println(pojo.getTemperatureMax());
                    System.out.println(pojo.getTemperatureMin());
                            
                    
                }
    }
}

 

cxf和jaxws的对比

标签:

原文地址:http://www.cnblogs.com/liuconglin/p/5657821.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!