当前位置:首页 > 开发 > 编程语言 > Web Service > 正文

webService

发表于: 2015-06-02   作者:后人生苟   来源:转载   浏览:
摘要: 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; im
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();
}
}

webService

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号