./wsdl2java.sh -uri http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl -p com.johnyu.stub
将生成的源码copy到项目下。
写出如下测试代码:
package com.johnyu.stub; import com.johnyu.stub.WeatherWebServiceStub.ArrayOfString; public class TestWeather { public static void main(String[] args) throws Exception{ WeatherWebServiceStub stub=new WeatherWebServiceStub(); WeatherWebServiceStub.GetSupportProvince getPro=new WeatherWebServiceStub.GetSupportProvince(); WeatherWebServiceStub.GetSupportCity getCity=new WeatherWebServiceStub.GetSupportCity(); WeatherWebServiceStub.GetWeatherbyCityName wether=new WeatherWebServiceStub.GetWeatherbyCityName(); //获取全国省份名称 ArrayOfString aos=stub.getSupportProvince(getPro).getGetSupportProvinceResult(); String[] pros=aos.getString(); for(String s:pros){ System.out.println(s); } //获取四川省的全部城市 getCity.setByProvinceName("四川"); ArrayOfString cos=stub.getSupportCity(getCity).getGetSupportCityResult(); String[] citis=cos.getString(); for(String s:citis){ System.out.println(s); } //获取成都的气象信息 wether.setTheCityName("成都"); String[] ws=stub.getWeatherbyCityName(wether).getGetWeatherbyCityNameResult().getString(); for(String s:ws){ System.out.println(s); } } }