一、安裝

          jsp程序員應該不會裝錯。首先下載axis,解壓縮。將axis目錄拷貝到tomcat下webapps下。ok,對就這么簡單。

          啟動tomcat,訪問http://localhost:8080/axis 檢查安裝是否成功

          二、部署(三種方式)

          (1)、Dynamic Invocation Interface ( DII)

          我認為這是其中最簡單的方式,也是最不想介紹的方式。

          1.編寫服務端程序HelloClient
            
          1   public class HelloClient
          2   {
          3       public String getName(String name)
          4       {
          5           return "hello "+name;
          6       }
          7   }

            
          2、將源碼拷貝到Axis_HOME下,重命名為 HelloClient.jws
            
          3、訪問連接http://localhost:8080/axis/HelloClient.jws?wsdl,頁面顯示Axis自動生成的wsdl
            
          4、編寫訪問服務的客戶端 TestHelloClient.java
            
            
           1 import org.apache.Axis.client.Call;
           2   import org.apache.Axis.client.Service;
           3   import javax.xml.namespace.QName;
           4   import javax.xml.rpc.ServiceException;
           5   import java.net.MalformedURLException;
           6   import java.rmi.RemoteException;
           7   
           8   public class SayHelloClient2
           9   {
          10    public static void main(String[] args)
          11    {
          12      try
          13      {
          14          String endpoint =
          15            "http://localhost:8080/Axis/HelloClient.jws";
          16   
          17           Service service = new Service();
          18           Call call = null;
          19   
          20           call = (Call) service.createCall();
          21   
          22           call.setOperationName(new QName(
          23       "http://localhost:8080/Axis/HelloClient.jws",
          24           "getName"));
          25           call.setTargetEndpointAddress
          26           (new java.net.URL(endpoint));
          27   
          28       String ret = (String) call.invoke(new Object[]
          29       {"zhangsan"});
          30       System.out.println("return value is " + ret);
          31   }
          32   catch (Exception ex)
          33   {
          34       ex.printStackTrace();
          35   }
          36   }
          37   }

            

            
          (2)、Stubs方式

          這種方式對自己來說記憶很深刻,做的第一個小項目,調用別人提供的ws就是這種方式。

              1、編寫部署服務端程序,同上邊DII方式,本次仍使用上邊部署的HelloClient
            
            2、編寫代理接口
            
          1   public interface HelloClientInterface
          2   extends java.rmi.Remote
          3   {
          4      public String getName(String name)
          5      throws java.rmi.RemoteException;
          6   }

            
            3、編寫并執行客戶端程序TestHelloClient.java
            
           1 
           2   import javax.xml.rpc.Service;
           3   import javax.xml.rpc.ServiceFactory;
           4   import java.net.URL;
           5   import javax.xml.namespace.QName;
           6   
           7   public class TestHelloClient
           8   {
           9   public static void main(String[] args)
          10   {
          11   try
          12   {
          13   String wsdlUrl =
          14   "http://localhost:8080/Axis/HelloClient.jws?wsdl";
          15   String nameSpaceUri =
          16   "http://localhost:8080/Axis/HelloClient.jws";
          17   String serviceName = "HelloClientService";
          18   String portName = "HelloClient";
          19   
          20   ServiceFactory serviceFactory =
          21   ServiceFactory.newInstance();
          22   Service afService =
          23   serviceFactory.createService(new URL(wsdlUrl),
          24   new QName(nameSpaceUri, serviceName));
          25   HelloClientInterface proxy = (HelloClientInterface)
          26   afService.getPort(new QName(
          27   nameSpaceUri, portName),
          28   HelloClientInterface.class);
          29   System.out.println
          30   ("return value is "+proxy.getName("john") ) ;
          31   }catch(Exception ex)
          32   {
          33   ex.printStackTrace() ;
          34   }
          35   }
          36   }


            
          (3)、Dynamic Proxy方式

          (我比較喜歡用這種方式。)

          1. 服務端同樣使用一樣的測試代碼,不過打包成jar,然后放在axis目錄web-inf/lib下。
          2. 編寫server-config.wsdd 放在axis web-inf下。
           1 
           2 <?xml version="1.0" encoding="UTF-8"?>
           3 <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
           4  <globalConfiguration>
           5   <parameter name="adminPassword" value="admin"/>
           6   <parameter name="enableNamespacePrefixOptimization" value="true"/>
           7   <parameter name="disablePrettyXML" value="true"/>
           8   <parameter name="sendXsiTypes" value="true"/>
           9   <parameter name="sendMultiRefs" value="true"/>
          10   <parameter name="sendXMLDeclaration" value="true"/>
          11   <requestFlow name="RequestFlow1">
          12    <handler name="Handler1" type="java:org.apache.axis.handlers.JWSHandler">
          13     <parameter name="scope" value="application"/>
          14    </handler>
          15    <handler name="Handler2" type="java:org.apache.axis.handlers.JWSHandler">
          16     <parameter name="scope" value="request"/>
          17     <parameter name="extension" value=".jwr"/>
          18    </handler>
          19   </requestFlow>
          20  </globalConfiguration>
          21  <responseFlow name="ResponseFlow1">
          22   <handler name="Handler1" type="LocalResponder"/>
          23  </responseFlow>
          24  <handler name="Handler1" type="LocalResponder"/>
          25  <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
          26  <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
          27  <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
          28  <handler name="Handler2" type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
          29  <requestFlow name="RequestFlow1">
          30   <handler name="Handler1" type="URLMapper"/>
          31   <handler name="Handler2" type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
          32  </requestFlow>
          33  
          34  <service name="TESTWS" style="wrapped">
          35   <parameter name="allowedMethods" value="*"/>
          36   <parameter name="scope" value="Application"/>
          37   <parameter name="className" value="HelloClient"/>
          38  </service>
          39 
          40  <transport name="http">
          41   <requestFlow name="RequestFlow1">
          42    <handler name="Handler1" type="URLMapper"/>
          43    <handler name="Handler2" type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
          44   </requestFlow>
          45  </transport>
          46  <transport name="local">
          47   <responseFlow name="ResponseFlow1">
          48    <handler name="Handler1" type="LocalResponder"/>
          49   </responseFlow>
          50  </transport>
          51 </deployment>


          測試程序仍然可以是DII方式中的測試程序。
          不過附帶vbs腳本測試:
          1 
          2 Set SOAPClient = CreateObject("MSSOAP.SOAPClient30")
          3 SOAPClient.MSSOAPInit("http://127.0.0.1:8080/axis/services/TESTWS?wsdl")
          4 WScript.Echo SOAPClient.getName("devTest")
          5 

          再附帶一個asp連接程序:

          1 Set SOAPClient = server.CreateObject("MSSOAP.SOAPClient30")
          2 SOAPClient.ClientProperty("ServerHTTPRequest"= True
          3 SOAPClient.MSSOAPInit("http://127.0.0.1:8080/axis/services/TESTWS?wsdl")
          4 Dim wsrequest=SOAPClient.getName("zhangsan")

          不過注意,vb 和asp連接應該裝 soapsdk.exe 和msxmlchs.msi軟件。
          posted on 2007-02-08 09:18 -274°C 閱讀(46969) 評論(0)  編輯  收藏 所屬分類: WebService

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網站

          關注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 916109
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 维西| 伊宁县| 昆山市| 平邑县| 修武县| 疏勒县| 洛宁县| 普陀区| 永定县| 漯河市| 桃江县| 新丰县| 福鼎市| 凤阳县| 浙江省| 扬中市| 徐水县| 文化| 马关县| 聂荣县| 蒙阴县| 会昌县| 霍林郭勒市| 车险| 中江县| 东至县| 沿河| 蓝山县| 明星| 蒙山县| 搜索| 扬州市| 文山县| 山阴县| 襄樊市| 凤凰县| 名山县| 富顺县| 贞丰县| 习水县| 新津县|