1. 程式人生 > >CXF 呼叫webservice客戶端步驟

CXF 呼叫webservice客戶端步驟

1、通過cxf用wsdl生成java客戶端檔案

下載apache的cxf檔案下本地,再用wsdl2java命令生成,並copy java到相應的目錄

2、客戶端程式碼

@Test
public void q30100(){

    //設定請求引數
    DTSaleArea2CityDistReq dtSaleArea2CityDistReq = new DTSaleArea2CityDistReq();
    dtSaleArea2CityDistReq.setBEGDATE("2017-11-02");

    //服務類
    SISaleArea2CityDistOutService service = new SISaleArea2CityDistOutService();
    SISaleArea2CityDistOut out = service.getHTTPPort();

    //設定webservice使用者名稱密碼,介面驗證
    BindingProvider bp = (BindingProvider) out;
    Map<String, Object> context = bp.getRequestContext();
    context.put(BindingProvider.USERNAME_PROPERTY, "pisuper");
    context.put(BindingProvider.PASSWORD_PROPERTY, "Transfar2016");

    //呼叫具體方法名稱
    DTSaleArea2CityDistRes dtSaleArea2CityDistRes = out.siSaleArea2CityDistOut(dtSaleArea2CityDistReq);

    List<DTSaleArea2CityDistRes.ITEMS> items  =  dtSaleArea2CityDistRes.getITEMS();

    for(DTSaleArea2CityDistRes.ITEMS item : items){
        System.out.println(item.getBZIRK()+" || "+item.getBZTXT()+" || "+item.getERDATE()+" || "+item.getPID());
    }
}