webservice--cxf和jaxws的對比


和jaxws相比,服務器發布方式和客戶端訪問方式不同

以下是cxf的代碼:

服務器發布方式:

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());
                            
                    
                }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM