<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    eclipse插件實現(xiàn)Java調(diào)用 asmx 的Web Service

    eclipse插件(axis2 tool--Code Generator Wizard)實現(xiàn)Java調(diào)用 asmx 的Web Service

    一個獲得天氣情況及國家城市的 Web Service
    http://www.webservicex.net/globalweather.asmx?WSDL

    AXIS2 下載地址 http://ws.apache.org/axis2/download.cgi
    其eclipse工具 http://ws.apache.org/axis2/tools/index.html
    Code Generator Wizard - Eclipse Plug-in 可以以eclipse中的link方式安裝.即可以通過自動
    生成java service code.

    具體步驟如下:
    在eclipse的java project中 NEW --> Other --> Axis2 Wizards -->Axis2 Code Generator
    NEXT --> 選擇 Generate java source code from a WSDL file
    NEXT --> 在WSDL file location: 中輸入 : http://www.webservicex.net/globalweather.asmx?WSDL
    NEXT --> NEXT --> 選擇好文件生成路徑
    如: E:\eclipseworkspace\axis213\src
    FINISH 后會自動生成兩個文件:
    GlobalWeatherCallbackHandler.java 和 GlobalWeatherStub.java

    新建一個測試文件GlobalWeatherTest.java.
    內(nèi)容如下:
    package net.webservicex.www;

    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.StringReader;
    import java.rmi.RemoteException;

    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;

    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;

    public class GlobalWeatherTest {
     public static void main(String[] args) throws RemoteException {
      GlobalWeatherStub stub = new GlobalWeatherStub();
      GlobalWeatherStub.GetCitiesByCountry request = new GlobalWeatherStub.GetCitiesByCountry();
      request.setCountryName("Korea");
      GlobalWeatherStub.GetCitiesByCountryResponse response = stub
        .GetCitiesByCountry(request);
      System.out.println("=================國家城市=================");
      //System.out.println(response.getGetCitiesByCountryResult());
      String xml = response.getGetCitiesByCountryResult();
      parseXML(xml);
      
      GlobalWeatherStub.GetWeather weatherRequest = new
      GlobalWeatherStub.GetWeather();
      weatherRequest.setCountryName("Korea");
      weatherRequest.setCityName("Seoul");
      GlobalWeatherStub.GetWeatherResponse weatherResponse =
      stub.GetWeather(weatherRequest);
      System.out.println("=================國家/城市/天氣=================");
      System.out.println(weatherResponse.getGetWeatherResult());
     }

     public static void parseXML(String xml) {
      DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
      try {
       DocumentBuilder dombuilder = domfac.newDocumentBuilder();
       StringReader rd = new StringReader(xml);
       InputSource is = new InputSource(rd);

       Document doc = dombuilder.parse(is);
       Element root = doc.getDocumentElement();
       NodeList citys = root.getChildNodes();

       if (citys != null) {
        for (int i = 0; i < citys.getLength(); i++) {
         Node city = citys.item(i);
         if (city.getNodeType() == Node.ELEMENT_NODE) {
          for (Node node = city.getFirstChild(); node != null; node = node
            .getNextSibling()) {
           if (node.getNodeType() == Node.ELEMENT_NODE) {
            if (node.getNodeName().equals("Country")) {
             String country = node.getFirstChild()
               .getNodeValue();
             System.out.print(country);
            }
            if (node.getNodeName().equals("City")) {
             String cityname = node.getFirstChild()
               .getNodeValue();
             System.out.println(" || " + cityname);
            }
           }
          }
         }
        }
       }
      } catch (ParserConfigurationException e) {
       e.printStackTrace();
      } catch (FileNotFoundException e) {
       e.printStackTrace();
      } catch (SAXException e) {
       e.printStackTrace();
      } catch (IOException e) {
       e.printStackTrace();
      }
     }
    }


    運行結(jié)果如下:

    =================國家城市=================
    Korea, Republic of || Kwangju Ab
    Korea, Republic of || Kunsan Ab
    Korea, Republic of || Yosu Airport
    Korea, Republic of || Chunchon Ab
    Korea, Republic of || Hoengsong Ab
    Korea, Republic of || Kangnung Ab
    Korea, Republic of || Wonju
    Korea, Republic of || Cheju International Airport
    Korea, Republic of || Pusan / Kimhae International Airport
    Korea, Republic of || Mosulpo Ab
    Korea, Republic of || Sach'On Ab
    Korea, Republic of || Ulsan
    Korea, Republic of || Tonghae Radar Site
    Korea, Republic of || Seoul / Yongdungp'O Rokaf Wc
    Korea, Republic of || Pyongtaek Ab
    Korea, Republic of || Seoul
    Korea, Republic of || Seoul E Ab
    Korea, Republic of || Koon-Ni Range
    Korea, Republic of || Osan Ab
    Korea, Republic of || Paengnyongdo Ab
    Korea, Republic of || Yeonpyeungdo
    Korea, Republic of || Seoul / Kimp'O International Airport
    Korea, Republic of || Yeoju Range
    Korea, Republic of || Suwon Ab
    Korea, Republic of || Camp Stanley / H-207
    Korea, Republic of || Yongsan / H-208 Hp
    Korea, Republic of || Andong
    Korea, Republic of || Paekado
    Korea, Republic of || Taejon Kor-Afb
    Korea, Republic of || Songmu Ab
    Korea, Republic of || Taejon
    Korea, Republic of || Pohang Ab
    Korea, Republic of || Jung Won Rok-Ab
    Korea, Republic of || Mangilsan Ab
    Korea, Republic of || Taegu Ab
    Korea, Republic of || Sangju
    Korea, Republic of || Taegu
    Korea, Republic of || Chongju Ab
    Korea, Republic of || Woong Cheon
    Korea, Republic of || Yechon Ab
    Korea, Democratic People's Republic of || Kimchaek
    Korea, Democratic People's Republic of || Pyongyang
    =================國家/城市/天氣=================
    <?xml version="1.0" encoding="utf-16"?>
    <CurrentWeather>
      <Location>Seoul / Kimp'O International Airport, Korea, South (RKSS) 37-33N 126-48E 18M</Location>
      <Time>Oct 24, 2007 - 11:00 AM EDT / 2007.10.24 1500 UTC</Time>
      <Wind> from the NNW (330 degrees) at 2 MPH (2 KT) (direction variable):0</Wind>
      <Visibility> less than 1 mile:0</Visibility>
      <SkyConditions> partly cloudy</SkyConditions>
      <Temperature> 48 F (9 C)</Temperature>
      <DewPoint> 48 F (9 C)</DewPoint>
      <RelativeHumidity> 100%</RelativeHumidity>
      <Pressure> 30.24 in. Hg (1024 hPa)</Pressure>
      <Status>Success</Status>
    </CurrentWeather>

    WSDL

    =============最新的axis2-eclipse-codegen-wizard-1.4 用法(20080806)==============

    用同樣的方法生成代碼有五個:
    GlobalWeather.java
    GlobalWeatherLocator.java
    GlobalWeatherSoap.java
    GlobalWeatherSoapProxy.java
    GlobalWeatherSoapStub.java

    客戶端調(diào)用如下:
    GlobalWeatherLocator gwl = new GlobalWeatherLocator();
    GlobalWeatherSoapStub binding = (GlobalWeatherSoapStub)gwl.getGlobalWeatherSoap();
    System.out.println(">>>"+binding.getCitiesByCountry("Korea"));
    System.out.println(binding.getWeather("Seoul", "Korea"));

    posted on 2013-04-06 10:37 youngturk 閱讀(3065) 評論(1)  編輯  收藏 所屬分類: Java基礎(chǔ)webService

    評論

    # re: eclipse插件實現(xiàn)Java調(diào)用 asmx 的Web Service [未登錄] 2013-05-23 09:33 tom

    非常感謝  回復(fù)  更多評論   

    <2013年4月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    導(dǎo)航

    統(tǒng)計

    公告

    this year :
    1 jQuery
    2 freemarker
    3 框架結(jié)構(gòu)
    4 口語英語

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    EJB學(xué)習(xí)

    Flex學(xué)習(xí)

    learn English

    oracle

    spring MVC web service

    SQL

    Struts

    生活保健

    解析文件

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 日韩一级在线播放免费观看| 亚洲欧洲日产国码无码网站| 亚洲乱码日产精品a级毛片久久| 久久久久久亚洲AV无码专区| 国产亚洲欧美日韩亚洲中文色| 久久国产乱子免费精品| 成人免费看黄20分钟| 久久久久亚洲AV无码专区首| 九九免费精品视频在这里| 永久免费看bbb| 亚洲愉拍一区二区三区| 18禁黄网站禁片免费观看不卡| 亚洲av无码专区国产乱码在线观看| 亚洲黄片手机免费观看| 亚洲国产精品激情在线观看| 一区二区免费在线观看| 中文字幕在亚洲第一在线 | 男女交性无遮挡免费视频| 国产精品jizz在线观看免费| 亚洲av无码片vr一区二区三区 | 全免费A级毛片免费看网站| 三年在线观看免费观看完整版中文| 亚洲女同成人AⅤ人片在线观看| 亚欧人成精品免费观看| 亚洲天堂男人影院| 成人免费看吃奶视频网站| 鲁丝片一区二区三区免费| 亚洲一区二区在线免费观看| 免费看a级黄色片| 91香蕉在线观看免费高清| 亚洲精品电影天堂网| 91香蕉国产线观看免费全集| 一级黄色片免费观看| 亚洲国产精品一区二区三区在线观看| 免费观看的a级毛片的网站| 99久久免费中文字幕精品| 久久亚洲精品专区蓝色区| 亚洲好看的理论片电影| 在线观看免费a∨网站| 欧洲美女大片免费播放器视频| 亚洲久悠悠色悠在线播放|