﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-insomnia,politic,proficient ,sensible.-随笔分类-webService</title><link>http://www.blogjava.net/youngturk/category/52623.html</link><description>The world is a fine place , and worth fighting for it.</description><language>zh-cn</language><lastBuildDate>Sun, 07 Apr 2013 08:03:02 GMT</lastBuildDate><pubDate>Sun, 07 Apr 2013 08:03:02 GMT</pubDate><ttl>60</ttl><item><title>eclipse插件实现Java调用 asmx 的Web Service </title><link>http://www.blogjava.net/youngturk/archive/2013/04/06/397421.html</link><dc:creator>youngturk</dc:creator><author>youngturk</author><pubDate>Sat, 06 Apr 2013 02:37:00 GMT</pubDate><guid>http://www.blogjava.net/youngturk/archive/2013/04/06/397421.html</guid><wfw:comment>http://www.blogjava.net/youngturk/comments/397421.html</wfw:comment><comments>http://www.blogjava.net/youngturk/archive/2013/04/06/397421.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/youngturk/comments/commentRss/397421.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/youngturk/services/trackbacks/397421.html</trackback:ping><description><![CDATA[<p>eclipse插件(axis2 tool--Code Generator Wizard)实现Java调用 asmx 的Web Service</p>
<p>一个获得天气情况及国家城市的 Web Service <br /><a href="http://www.webservicex.net/globalweather.asmx?WSDL">http://www.webservicex.net/globalweather.asmx?WSDL</a> </p>
<p>AXIS2 下载地址 <a href="http://ws.apache.org/axis2/download.cgi">http://ws.apache.org/axis2/download.cgi</a><br />其eclipse工具 <a href="http://ws.apache.org/axis2/tools/index.html">http://ws.apache.org/axis2/tools/index.html</a><br />Code Generator Wizard - Eclipse Plug-in 可以以eclipse中的link方式安装.即可以通过自动<br />生成java service code.</p>
<p>具体步骤如下：<br />在eclipse的java project中 NEW --&gt; Other --&gt; Axis2 Wizards --&gt;Axis2 Code Generator <br />NEXT --&gt; 选择 Generate java source code from a WSDL file<br />NEXT --&gt; 在WSDL file location: 中输入 : <a href="http://www.webservicex.net/globalweather.asmx?WSDL">http://www.webservicex.net/globalweather.asmx?WSDL</a><br />NEXT --&gt; NEXT --&gt; 选择好文件生成路径<br />如: E:\eclipseworkspace\axis213\src<br />FINISH 后会自动生成两个文件：<br />GlobalWeatherCallbackHandler.java 和 GlobalWeatherStub.java</p>
<p>新建一个测试文件GlobalWeatherTest.java.<br />内容如下:<br />package net.webservicex.www;</p>
<p>import java.io.FileNotFoundException;<br />import java.io.IOException;<br />import java.io.StringReader;<br />import java.rmi.RemoteException;</p>
<p>import javax.xml.parsers.DocumentBuilder;<br />import javax.xml.parsers.DocumentBuilderFactory;<br />import javax.xml.parsers.ParserConfigurationException;</p>
<p>import org.w3c.dom.Document;<br />import org.w3c.dom.Element;<br />import org.w3c.dom.Node;<br />import org.w3c.dom.NodeList;<br />import org.xml.sax.InputSource;<br />import org.xml.sax.SAXException;</p>
<p>public class GlobalWeatherTest {<br />&nbsp;public static void main(String[] args) throws RemoteException {<br />&nbsp;&nbsp;GlobalWeatherStub stub = new GlobalWeatherStub();<br />&nbsp;&nbsp;GlobalWeatherStub.GetCitiesByCountry request = new GlobalWeatherStub.GetCitiesByCountry();<br />&nbsp;&nbsp;request.setCountryName("Korea");<br />&nbsp;&nbsp;GlobalWeatherStub.GetCitiesByCountryResponse response = stub<br />&nbsp;&nbsp;&nbsp;&nbsp;.GetCitiesByCountry(request);<br />&nbsp;&nbsp;System.out.println("=================国家城市=================");<br />&nbsp;&nbsp;//System.out.println(response.getGetCitiesByCountryResult());<br />&nbsp;&nbsp;String xml = response.getGetCitiesByCountryResult();<br />&nbsp;&nbsp;parseXML(xml);<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;GlobalWeatherStub.GetWeather weatherRequest = new<br />&nbsp;&nbsp;GlobalWeatherStub.GetWeather();<br />&nbsp;&nbsp;weatherRequest.setCountryName("Korea");<br />&nbsp;&nbsp;weatherRequest.setCityName("Seoul");<br />&nbsp;&nbsp;GlobalWeatherStub.GetWeatherResponse weatherResponse =<br />&nbsp;&nbsp;stub.GetWeather(weatherRequest);<br />&nbsp;&nbsp;System.out.println("=================国家/城市/天气=================");<br />&nbsp;&nbsp;System.out.println(weatherResponse.getGetWeatherResult());<br />&nbsp;}</p>
<p>&nbsp;public static void parseXML(String xml) {<br />&nbsp;&nbsp;DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();<br />&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;DocumentBuilder dombuilder = domfac.newDocumentBuilder();<br />&nbsp;&nbsp;&nbsp;StringReader rd = new StringReader(xml);<br />&nbsp;&nbsp;&nbsp;InputSource is = new InputSource(rd);</p>
<p>&nbsp;&nbsp;&nbsp;Document doc = dombuilder.parse(is);<br />&nbsp;&nbsp;&nbsp;Element root = doc.getDocumentElement();<br />&nbsp;&nbsp;&nbsp;NodeList citys = root.getChildNodes();</p>
<p>&nbsp;&nbsp;&nbsp;if (citys != null) {<br />&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; citys.getLength(); i++) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Node city = citys.item(i);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (city.getNodeType() == Node.ELEMENT_NODE) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (Node node = city.getFirstChild(); node != null; node = node<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getNextSibling()) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (node.getNodeType() == Node.ELEMENT_NODE) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (node.getNodeName().equals("Country")) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String country = node.getFirstChild()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getNodeValue();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(country);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (node.getNodeName().equals("City")) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String cityname = node.getFirstChild()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getNodeValue();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(" || " + cityname);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;} catch (ParserConfigurationException e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;} catch (FileNotFoundException e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;} catch (SAXException e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;} catch (IOException e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;}<br />&nbsp;}<br />}</p>
<p><br />运行结果如下:</p>
<p>=================国家城市=================<br />Korea, Republic of || Kwangju Ab<br />Korea, Republic of || Kunsan Ab<br />Korea, Republic of || Yosu Airport<br />Korea, Republic of || Chunchon Ab<br />Korea, Republic of || Hoengsong Ab<br />Korea, Republic of || Kangnung Ab<br />Korea, Republic of || Wonju<br />Korea, Republic of || Cheju International Airport<br />Korea, Republic of || Pusan / Kimhae International Airport<br />Korea, Republic of || Mosulpo Ab<br />Korea, Republic of || Sach'On Ab<br />Korea, Republic of || Ulsan<br />Korea, Republic of || Tonghae Radar Site<br />Korea, Republic of || Seoul / Yongdungp'O Rokaf Wc<br />Korea, Republic of || Pyongtaek Ab<br />Korea, Republic of || Seoul<br />Korea, Republic of || Seoul E Ab<br />Korea, Republic of || Koon-Ni Range<br />Korea, Republic of || Osan Ab<br />Korea, Republic of || Paengnyongdo Ab<br />Korea, Republic of || Yeonpyeungdo<br />Korea, Republic of || Seoul / Kimp'O International Airport<br />Korea, Republic of || Yeoju Range<br />Korea, Republic of || Suwon Ab<br />Korea, Republic of || Camp Stanley / H-207<br />Korea, Republic of || Yongsan / H-208 Hp<br />Korea, Republic of || Andong<br />Korea, Republic of || Paekado<br />Korea, Republic of || Taejon Kor-Afb<br />Korea, Republic of || Songmu Ab<br />Korea, Republic of || Taejon<br />Korea, Republic of || Pohang Ab<br />Korea, Republic of || Jung Won Rok-Ab<br />Korea, Republic of || Mangilsan Ab<br />Korea, Republic of || Taegu Ab<br />Korea, Republic of || Sangju<br />Korea, Republic of || Taegu<br />Korea, Republic of || Chongju Ab<br />Korea, Republic of || Woong Cheon<br />Korea, Republic of || Yechon Ab<br />Korea, Democratic People's Republic of || Kimchaek<br />Korea, Democratic People's Republic of || Pyongyang<br />=================国家/城市/天气=================<br />&lt;?xml version="1.0" encoding="utf-16"?&gt;<br />&lt;CurrentWeather&gt;<br />&nbsp; &lt;Location&gt;Seoul / Kimp'O International Airport, Korea, South (RKSS) 37-33N 126-48E 18M&lt;/Location&gt;<br />&nbsp; &lt;Time&gt;Oct 24, 2007 - 11:00 AM EDT / 2007.10.24 1500 UTC&lt;/Time&gt;<br />&nbsp; &lt;Wind&gt; from the NNW (330 degrees) at 2 MPH (2 KT) (direction variable):0&lt;/Wind&gt;<br />&nbsp; &lt;Visibility&gt; less than 1 mile:0&lt;/Visibility&gt;<br />&nbsp; &lt;SkyConditions&gt; partly cloudy&lt;/SkyConditions&gt;<br />&nbsp; &lt;Temperature&gt; 48 F (9 C)&lt;/Temperature&gt;<br />&nbsp; &lt;DewPoint&gt; 48 F (9 C)&lt;/DewPoint&gt;<br />&nbsp; &lt;RelativeHumidity&gt; 100%&lt;/RelativeHumidity&gt;<br />&nbsp; &lt;Pressure&gt; 30.24 in. Hg (1024 hPa)&lt;/Pressure&gt;<br />&nbsp; &lt;Status&gt;Success&lt;/Status&gt;<br />&lt;/CurrentWeather&gt;</p>
<p>WSDL </p>
<p>=============最新的axis2-eclipse-codegen-wizard-1.4 用法(20080806)==============</p>
<p>用同樣的方法生成代碼有五個: <br />GlobalWeather.java<br />GlobalWeatherLocator.java<br />GlobalWeatherSoap.java<br />GlobalWeatherSoapProxy.java<br />GlobalWeatherSoapStub.java</p>
<p>客戶端調用如下:<br />GlobalWeatherLocator gwl = new GlobalWeatherLocator();<br />GlobalWeatherSoapStub binding = (GlobalWeatherSoapStub)gwl.getGlobalWeatherSoap();<br />System.out.println("&gt;&gt;&gt;"+binding.getCitiesByCountry("Korea"));<br />System.out.println(binding.getWeather("Seoul", "Korea"));<br /></p><img src ="http://www.blogjava.net/youngturk/aggbug/397421.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/youngturk/" target="_blank">youngturk</a> 2013-04-06 10:37 <a href="http://www.blogjava.net/youngturk/archive/2013/04/06/397421.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Apache axis2 + Eclipse 开发 WebService </title><link>http://www.blogjava.net/youngturk/archive/2013/03/21/396822.html</link><dc:creator>youngturk</dc:creator><author>youngturk</author><pubDate>Thu, 21 Mar 2013 14:16:00 GMT</pubDate><guid>http://www.blogjava.net/youngturk/archive/2013/03/21/396822.html</guid><wfw:comment>http://www.blogjava.net/youngturk/comments/396822.html</wfw:comment><comments>http://www.blogjava.net/youngturk/archive/2013/03/21/396822.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/youngturk/comments/commentRss/396822.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/youngturk/services/trackbacks/396822.html</trackback:ping><description><![CDATA[<u><a href="http://blog.csdn.net/xiaochunyong/article/details/7764683">http://blog.csdn.net/xiaochunyong/article/details/7764683</a><br /><a href="http://wenku.baidu.com/view/b3c7f14033687e21af45a98a.html">http://wenku.baidu.com/view/b3c7f14033687e21af45a98a.html</a>###</u><img src ="http://www.blogjava.net/youngturk/aggbug/396822.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/youngturk/" target="_blank">youngturk</a> 2013-03-21 22:16 <a href="http://www.blogjava.net/youngturk/archive/2013/03/21/396822.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>