直接使用wsimport 通过该地址生存java 文件时,会报错。因为该wsdl里面包含 ref = s:schema 这样的引用。而jaxb是不支持的。所以手动将该wsdl下载下来做下修改,然后再生成java文件。
修改方法为:
将所有的
然后再通过wsimport生成java文件。 如果还是报错,就将wsdl文件里面的
生成好java文件之后 ,开始我们的旅程吧。
1.生成好java文件

2.经过改良,我们自己写的服务
由于生成的代码,返回类型都是它给我们提供的ArrayOfString,我们可以把其中的数据解析成为map
接口
package com.webservice.weather;
import java.util.Map;
public interface WeatherService {
public Map
getSupportCity(String province);
public Map
getSupportProvince(); public Map
getWeatherbyCityName(String ctiy); }
实现类
package com.webservice.weather;
import java.util.LinkedHashMap;
import java.util.Map;
import cn.com.webxml.ArrayOfString;
import cn.com.webxml.WeatherWebService;
import cn.com.webxml.WeatherWebServiceSoap;
public class WeatherServiceImpl implements WeatherService {
public Map
getSupportCity(String province) {
WeatherWebService wws = new WeatherWebService();
WeatherWebServiceSoap soap = wws.getWeatherWebServiceSoap();
ArrayOfString aos = soap.getSupportCity (province);
Map
map = new LinkedHashMap
(); for (String s : aos.getString()) { map.put(s.substring(s.indexOf(()+1, s.indexOf())), s.substring(0, s.indexOf(()).trim()); } return map; } public Map
getSupportProvince() { WeatherWebService wws = new WeatherWebService(); WeatherWebServiceSoap soap = wws.getWeatherWebServiceSoap(); ArrayOfString aos = soap.getSupportProvince (); Map
map = new LinkedHashMap
(); for (String s : aos.getString()) { map.put(s, s); } return map; } public Map
getWeatherbyCityName(String ctiy) { WeatherWebService wws = new WeatherWebService(); WeatherWebServiceSoap soap = wws.getWeatherWebServiceSoap(); ArrayOfString aos = soap.getWeatherbyCityName (ctiy); Map
map = new LinkedHashMap
(); String[] key = new String[]{province,cityname,citycode,cityjpg,lastupdate, intradayTemp,generalSituation,WindDirectionAndForce ,beginTendencyJpg,endTendencyJpg,now,exponent, intradayTemp2,generalSituation2,WindDirectionAndForce2,beginTendencyJpg2,endTendencyJpg2, intradayTemp3,intradayTemp3,WindDirectionAndForce3,beginTendencyJpg3,endTendencyJpg3, areaInfo}; int index = 0; for (String s : aos.getString()) { map.put(key[index], s); index++; } return map; } }
3.调用的action类,这里我们用的是struts2提供的json插件,由struts2直接给我们返回json数据
package net.itcast.action;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
import com.webservice.weather.WeatherService;
import com.webservice.weather.WeatherServiceImpl;
@SuppressWarnings(serial)
public class WeatherAction extends ActionSupport{
private String provinceParam;
private String cityParam;
private Map
provinceMap;
private Map
cityMap; private Map
weatherMap; private WeatherService service = new WeatherServiceImpl(); public String querySupportCity () { cityMap = service.getSupportCity(provinceParam); return suppCity; } public String querySupportProvince () { provinceMap = service.getSupportProvince(); return suppProvince; } public String queryWeatherbyCityName () { weatherMap = service.getWeatherbyCityName(cityParam); return weatherinfo; } public String getProvinceParam() { return provinceParam; } public void setProvinceParam(String provinceParam) { this.provinceParam = provinceParam; } public String getCityParam(