加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webService

发布时间:2020-12-16 22:47:45 所属栏目:安全 来源:网络整理
导读: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.jaxw
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{ //? getStockInformation(); //? getWeatherInformation(); ? ? 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 getWeatherInformation()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 getStockInformation()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(); } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读