微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

webService

package cn.com.client.test; import java.io.BufferedInputStream; import java.io.bufferedoutputstream; import java.io.FileOutputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.apache.cxf.jaxws.JaxWsProxyfactorybean; import org.apache.cxf.service.Service; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import cn.com.webxml.arrayofstring; import cn.com.webxml.DataSet; import cn.com.webxml.GetWeatherbyCityName; import cn.com.webxml.WeatherWebServiceHttpPost; import cn.com.webxml.WeatherWebServiceSoap; import cn.com.webxml.GetSupportDataSetResponse.GetSupportDataSetResult; public class ClientTest { public static void main(String[] args) throws Exception{ //  getStock@R_106_4045@ion(); //  getWeather@R_106_4045@ion();     JaxWsProxyfactorybean factory = new JaxWsProxyfactorybean();   factory.setAddress("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");   factory.setServiceClass(WeatherWebServiceSoap.class);   WeatherWebServiceSoap wwss = (WeatherWebServiceSoap) factory.create();   //  arrayofstring aos = wwss.getSupportProvince(); //  List aList = aos.getString(); //  for (int i = 0; i < aList.size(); i++) { //   System.out.println(i+"-洲或国内省份的名称-"+aList.get(i)); //  }   //  arrayofstring b = wwss.getSupportCity("ALL"); //  List bList = b.getString(); //  for (int i = 0; i < bList.size(); i++) { //   System.out.println(i+"-城市名称(城市代码)-"+bList.get(i)); //  }   //  arrayofstring c = wwss.getWeatherbyCityNamePro("深圳","商业用户Id编号"); //  List cList = c.getString(); //  for (int i = 0; i < cList.size(); i++) { //   System.out.println(i+"-天气情况-"+cList.get(i)); //  }   //  GetSupportDataSetResult obj = wwss.getSupportDataSet();     arrayofstring d = wwss.getWeatherbyCityName("深圳");   List dList = d.getString();   for (int i = 0; i < dList.size(); i++) {    System.out.println("-----"+dList.get(i));   }   } public void asdf()throws Exception{ } public static void getWeather@R_106_4045@ion()throws Exception{   HttpGet get = new HttpGet("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=广州");   HttpClient client = new DefaultHttpClient();   HttpResponse response = client.execute(get);   InputStream is = response.getEntity().getContent();   byte b[] =  new byte[1024];   StringBuilder sb = new StringBuilder();   while(is.read(b)!= -1){    sb.append(new String(b,"utf-8"));   }   System.out.println("----天气信息:"+sb.toString()); } public static void getStock@R_106_4045@ion()throws Exception{   HttpGet get = new HttpGet("http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx/getStockImageByCode?theStockCode=");   HttpClient client = new DefaultHttpClient();   HttpResponse response = client.execute(get);   InputStream is = response.getEntity().getContent();   FileOutputStream fos = new FileOutputStream("E:/stock.gif");   BufferedInputStream bis = new BufferedInputStream(is);   bufferedoutputstream bos = new bufferedoutputstream(fos);   int b = 0 ;   while((b=bis.read()) != -1){    bos.write(b);   }   bis.close();   bos.close(); } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐