e.printStackTrace(); }
return cityCode; }
public static InputStream getSoapInputStream(String url){ InputStream inputStream = null; try{
URL urlObj = new URL(url);
URLConnection urlConn = urlObj.openConnection();
urlConn.setRequestProperty(\, SERVICES_HOST); //具体webService相关
urlConn.connect();
inputStream = urlConn.getInputStream(); }catch(MalformedURLException e){ e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); }
return inputStream; }
public static List
DocumentBuilderFactory documentBF = DocumentBuilderFactory.newInstance(); documentBF.setNamespaceAware(true); try{
DocumentBuilder documentB = documentBF.newDocumentBuilder(); InputStream inputStream =
getSoapInputStream(WEATHER_QUERY_URL + cityCode); document = documentB.parse(inputStream);
NodeList nl = document.getElementsByTagName(\); int len = nl.getLength(); for(int i = 0; i < len; i++){ Node n = nl.item(i);
String weather = n.getFirstChild().getNodeValue(); weatherList.add(weather); }
inputStream.close();
}catch(UnsupportedEncodingException e){ e.printStackTrace(); }catch (DOMException e){
e.printStackTrace();
}catch (ParserConfigurationException e){ e.printStackTrace(); }catch(SAXException e){ e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); }
return weatherList; } }
说明:该天气预报WebServices是上海思集信息科技有限公司提供的免费天气预报查询接口 程序中getProvinceCode是通过省份名获得provinceCode,getCityCode是通过provinceCode和地区名获得cityCode,而getWeather是通过cityCode获取该地区五天的天气预报返回类型为list,因此该程序必须在jdk1.5(或以上)环境中执行。
该文档由宽文是风向大春编写,仅供学习交流使用,里面的代码都是经过实践测试过的,文档中有什么不正确之处敬请指出。
该文档中的Demo只讲了axis中WebServices的定制发布,因为及时发布有局限性一般用得很少,不过在我附的资料里有讲解,大家自己感兴趣可以看看