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{
// 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();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值