andyj2ee

          java tec sky

          統(tǒng)計(jì)

          留言簿(4)

          activemq

          aop

          design pattern

          other blog

          spring

          workflow

          多線程

          軟件架構(gòu)師

          閱讀排行榜

          評(píng)論排行榜

          jsp 調(diào)用webservice 實(shí)例

          安裝Axis (Install Axis)

           

          1.  Download axis-1_1-src.tar

          http://ws.apache.org/axis/

          http://ws.apache.org/axis/download.cgi

          2.  unpack to d:/axis-1_1

          3.配置系統(tǒng)環(huán)境變量

          Windows:
          set AXIS_HOME=D:\opensource\axis\axis-1_1
          set AXIS_LIB=%AXIS_HOME%\lib
          set AXISCLASSPATH=%AXIS_LIB%\axis.jar;
          %AXIS_LIB%\commons-discovery.jar;
          %AXIS_LIB%\commons-logging.jar;
          %AXIS_LIB%\jaxrpc.jar;
          %AXIS_LIB%\saajjar;
          %AXIS_LIB%\log4j-1.2.8.jar;
          %AXIS_LIB%\saaj.jar;
          %AXIS_LIB%\wsdl4j.jar;


          How to use WSDL2Java

          Given a WSDL file of a web service you can manually code a client based on your understanding of WSDL document or you can use a tool to do that for you. This is very handy when WSDL is very complex. Axis provides such tool. Here is the command that you can run on GoogleSeach.wsdl.

          java org.apache.axis.wsdl.WSDL2Java --verbose GoogleSearch.wsdl

          Make sure that you have axis.jar file in your classpath while executing this command, as that is where org.apache.axis.wsdl.WSDL2Java resides.

          You will find a number of .java files generated in a subdirectory named GoogleSearch. These are the stub files or wrapper classes. The wrapper classes allow you to code in java data types and convert them transparently to XML.

          在網(wǎng)上google 一個(gè)有效的wsdl:
          http://www.webservicex.com/stockquote.asmx?WSDL

          生成java 類
          D:\projects\test\webservice\src>java org.apache.axis.wsdl.WSDL2Java --verbose http://www.webservicex.com/stockquote.asmx?WSDL

          Parsing XML file:  http://www.webservicex.com/stockquote.asmx?WSDL
          Generating NET\webserviceX\www\StockQuote.java
          Generating NET\webserviceX\www\StockQuoteLocator.java
          Generating NET\webserviceX\www\StockQuoteSoap.java
          Generating NET\webserviceX\www\StockQuoteSoapStub.java

          建立工程寫 java test
          import NET.webserviceX.www.StockQuoteLocator;
          import NET.webserviceX.www.StockQuoteSoap;


          /**
           * @author andy.zhang
           
          */

          public class Test {
              
          public static void main(String[] arg){
                  StockQuoteLocator binding
          =new StockQuoteLocator();
                     
          try {
                          StockQuoteSoap port
          =binding.getStockQuoteSoap();
                          String str
          =port.getQuote("IBM");
                          System.
          out.println(str);
                     }

                     
          catch(Exception e){
                     }

              }

          }




          運(yùn)行測(cè)試:
          D:\projects\test\webservice\classes>java -classpath %classpath%;.;NET.webservice
          X.www.*; Test

          <StockQuotes>
              
          <Stock>
                  
          <Symbol>IBM</Symbol>
                  
          <Last>92.37</Last>        
                  
          <Date>3/4/2005</Date>
                  
          <Time>4:00pm</Time>
                  
          <Change>-0.04</Change>
                  
          <Open>92.94</Open>
                  
          <High>93.18</High>
                  
          <Low>92.36</Low>
                  
          <Volume>4754000</Volume>
                  
          <MktCap>150.8B</MktCap>
                  
          <PreviousClose>92.41</PreviousClose>
                  
          <PercentageChange>-0.04%</PercentageChange>
                  
          <AnnRange>81.90 - 99.10</AnnRange>
                  
          <Earns>4.94</Earns>
                  
          <P-E>18.71</P-E>
                  
          <Name>INTL BUSINESS MAC</Name>
              
          </Stock>
          </StockQuotes>



          D:\projects\test\webservice\classes>
          成功了。:)


          這樣,就完成了對(duì).NET WebService端的調(diào)用。

          (data filetype:mdb)




          方向:分布式系統(tǒng)設(shè)計(jì)

          posted on 2005-03-07 15:52 java光環(huán) 閱讀(5830) 評(píng)論(3)  編輯  收藏 所屬分類: webservice

          評(píng)論

          # re: jsp 調(diào)用webservice 實(shí)例 2005-03-07 19:00 candy_liu

          好文章!
          補(bǔ)充一下:
          對(duì)方的wsdl 文件
          就是xml 文件,在文件中說(shuō)明了,這個(gè)webservice 提供了那些方法可以調(diào)用。
          然后 生成工具根據(jù) wsdl文件 的描述,生成相應(yīng)的骨架代碼

          用骨架代碼 就能寫程序了
            回復(fù)  更多評(píng)論   

          # re: jsp 調(diào)用webservice 實(shí)例 2005-11-25 11:56 Ray

          好好啊!
          受益匪淺!  回復(fù)  更多評(píng)論   

          # re: jsp 調(diào)用webservice 實(shí)例 2006-12-11 16:50 a[匿名]

          請(qǐng)問(wèn),我用JBUILDER2006自動(dòng)生成客戶端然后在想在JSP中調(diào)用,可是總是不能實(shí)例化類是為什么,如果不能實(shí)例化類那怎么調(diào)用里面的方法取出來(lái)數(shù)值呢  回復(fù)  更多評(píng)論   


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 芜湖县| 沽源县| 邛崃市| 墨竹工卡县| 鲁甸县| 东辽县| 会理县| 拉孜县| 华宁县| 汤阴县| 利川市| 贵德县| 兴业县| 旬阳县| 长葛市| 常山县| 双城市| 嘉黎县| 东海县| 玉门市| 溧水县| 盖州市| 柳州市| 嘉义县| 临海市| 漳平市| 盐池县| 手游| 周至县| 西城区| 屏东市| 孟村| 富平县| 西乡县| 凭祥市| 黑水县| 博爱县| 黄浦区| 蛟河市| 宜川县| 湖南省|