在自己的工程里发布webservice的步骤(3)

2018-11-23 20:16

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 getWeather(int cityCode){ List weatherList = new ArrayList(); Document document;

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的定制发布,因为及时发布有局限性一般用得很少,不过在我附的资料里有讲解,大家自己感兴趣可以看看


在自己的工程里发布webservice的步骤(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:厂房、生产设施和设备变更风险评估

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: