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

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

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

    posts - 495,comments - 227,trackbacks - 0
    一、axis安裝
    1.環境
    ??J2SE?SDK?1.3?or?1.4:??我使用?1.4.2
    ???Servlet?Container:?我使用Tomcat?5.0?
    2.到?http://ws.apache.org/axis/網站下載axis安裝包
    3.解壓縮安裝包,將AXIS_UNZIP_PATH\axis-version\webapps下的axis包拷貝到TOMCAT_HOME\webapps\下,
    ????以下約定AXIS_HOME為該TOMCAT_HOME\webapps\axis目錄
    4.啟動tomcat,訪問http://localhost:8080/axis?檢查安裝是否成功
    5.以上步驟執行成功,可以開發webservice例子了

    axis支持三種web?service的部署和開發,分別為:
    1。Dynamic?Invocation?Interface?(?DII)
    2。?Stubs方式
    3。Dynamic?Proxy方式

    以下逐一講述web?service在axis上的部署和開發,設置classpath
    set?CLASSPATH=.;%AXIS_HOME%\lib\axis.jar;%AXIS_HOME%\lib\axis-ant.jar;%AXIS_HOME%\lib\commons-discovery-0.2.jar;%AXIS_HOME%\lib\commons-logging-1.0.4.jar;%AXIS_HOME%\lib\jaxrpc.jar;%AXIS_HOME%\lib\saaj.jar;%AXIS_HOME%\lib\wsdl4j-1.5.1.jar;%AXIS_HOME%\lib\log4j-1.2.8.jar;E:/thirdparty/activation/activation.jar;E:/thirdparty/activation/mail.jar



    二、編寫DII(Dynamic?Invocation?Interface?)方式web服務
    1.編寫服務端程序HelloClient
    public?class?HelloClient?{
    ????public?String?getName(String?name)
    ????{
    ????????return?"hello?"+name;
    ????}
    }

    2.將源碼拷貝到AXIS_HOME下,重命名為?HelloClient.jws
    3.訪問連接http://localhost:8080/axis/HelloClient.jws?wsdl,頁面顯示axis自動生成的wsdl
    4.編寫訪問服務的客戶端?TestHelloClient.java

    import?org.apache.axis.client.Call;
    import?org.apache.axis.client.Service;
    import?javax.xml.namespace.QName;
    import?javax.xml.rpc.ServiceException;
    import?java.net.MalformedURLException;
    import?java.rmi.RemoteException;

    public?class?SayHelloClient2?{
    ????public?static?void?main(String[]?args)?{
    ????????try?{
    ????????????String?endpoint?=?"http://localhost:8080/axis/HelloClient.jws";

    ????????????Service?service?=?new?Service();
    ????????????Call?call?=?null;

    ????????????call?=?(Call)?service.createCall();

    ????????????call.setOperationName(new?QName(
    ????????????????????"http://localhost:8080/axis/HelloClient.jws",?"getName"));
    ????????????call.setTargetEndpointAddress(new?java.net.URL(endpoint));

    ????????????String?ret?=?(String)?call.invoke(new?Object[]?{"zhangsan"});
    ????????????System.out.println("return?value?is?"?+?ret);
    ????????}?catch?(Exception?ex)?{
    ????????????ex.printStackTrace();
    ????????}
    ????}
    }
    三、編寫Dynamic?Proxy方式訪問服務
    1.編寫部署服務端程序,同上邊DII方式,本次仍使用上邊部署的HelloClient
    2.編寫代理接口
    public?interface?HelloClientInterface?extends?java.rmi.Remote?{
    ????public?String?getName(String?name)?throws?java.rmi.RemoteException;
    }
    3.編寫并執行客戶端程序TestHelloClient.java

    import?javax.xml.rpc.Service;
    import?javax.xml.rpc.ServiceFactory;
    import?java.net.URL;
    import?javax.xml.namespace.QName;

    public?class?TestHelloClient?{
    ????public?static?void?main(String[]?args)?{
    ????????try
    ????????{
    ????????????String?wsdlUrl?=?"http://localhost:8080/axis/HelloClient.jws?wsdl";
    ????????????String?nameSpaceUri?=?"http://localhost:8080/axis/HelloClient.jws";
    ????????????String?serviceName?=?"HelloClientService";
    ????????????String?portName?=?"HelloClient";

    ????????????ServiceFactory?serviceFactory?=?ServiceFactory.newInstance();
    ????????????Service?afService?=?serviceFactory.createService(new?URL(wsdlUrl),
    ????????????????????new?QName(nameSpaceUri,?serviceName));
    ????????????HelloClientInterface?proxy?=?(HelloClientInterface)
    ???????????????????????????????????????????afService.getPort(new?QName(
    ????????????????????nameSpaceUri,?portName),?HelloClientInterface.class);
    ????????????System.out.println("return?value?is?"+proxy.getName("john")?)?;
    ????????}catch(Exception?ex)
    ????????{
    ????????????ex.printStackTrace()?;
    ????????}
    ????}
    }

    四、編寫wsdd發布web服務,編寫stub?client訪問web服務

    1.編寫服務端程序server,SayHello.java,編譯server.SayHello.java????
    package?server;
    public?class?SayHello?{
    ????public?String?getName(String?name)
    ????{
    ????????return?"hello?"+name;
    ????}
    }
    2.編寫LogHandler.java
    import?org.apache.axis.AxisFault;
    import?org.apache.axis.Handler;
    import?org.apache.axis.MessageContext;
    import?org.apache.axis.handlers.BasicHandler;

    import?java.util.Date;

    public?class?LogHandler?extends?BasicHandler?{
    ????public?void?invoke(MessageContext?msgContext)?throws?AxisFault
    ????{
    ????????/**?Log?an?access?each?time?we?get?invoked.
    ?????????*/
    ????????try?{
    ????????????Handler?serviceHandler?=?msgContext.getService();

    ????????????Integer?numAccesses?=
    ?????????????????????????????(Integer)serviceHandler.getOption("accesses");
    ????????????if?(numAccesses?==?null)
    ????????????????numAccesses?=?new?Integer(0);

    ????????????numAccesses?=?new?Integer(numAccesses.intValue()?+?1);

    ????????????Date?date?=?new?Date();
    ????????????String?result?=?date?+?":?service?"?+
    ????????????????????????????msgContext.getTargetService()?+
    ????????????????????????????"?accessed?"?+?numAccesses?+?"?time(s).";
    ????????????serviceHandler.setOption("accesses",?numAccesses);

    ????????????System.out.println(result);
    ????????}?catch?(Exception?e)?{
    ????????????throw?AxisFault.makeFault(e);
    ????????}
    ????}
    }
    3..編寫wsdd文件
    deploy.wsdd
    <deployment?xmlns="http://xml.apache.org/axis/wsdd/"
    ????????????xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">???????????
    ????????
    ?<handler?name="print"?type="java:LogHandler"/>?
    ?<service?name="sayhello"?provider="java:RPC">
    ???<requestFlow>
    ?????<handler?type="print"/>
    ???</requestFlow>
    ??<parameter?name="className"?value="server.SayHello"/>
    ??<parameter?name="allowedMethods"?value="*"/>??
    ?</service>
    </deployment>

    3.將編譯后的文件拷貝到AXIS_HOME/WEB-INF/classes下,如:D:\tomcat\webapps\axis\WEB-INF\classes
    4.發布服務:
    java?org.apache.axis.client.AdminClient?deploy.wsdd
    5.生成client?stub文件
    ???a:方式1
    ??????將SayHello.java拷貝到AXIS_HOME/下,重命名為SayHello.jws,執行下面的命令生存client?stub
    ??????java?org.apache.axis.wsdl.WSDL2Java??-p?client??http://localhost:8080/axis/services/SayHello.jws?wsdl
    ????b:方式2
    ????執行如下命令生成SayHello.wsdl
    ?????????java?org.apache.axis.wsdl.Java2WSDL?-oSayHello.wsdl?-lhttp://localhost:8080/axis/services/SayHello?-nsayhello?server.SayHello
    ??????????執行如下命令生成client?stub
    ??????java?org.apache.axis.wsdl.WSDL2Java??SayHello.wsdl??-p?client
    ???生成的stub?client文件列表為:
    ???1。SayHello.java
    ???2。SayHelloService.java。
    ???3。SayHelloServiceLocator.java
    ???4。SayHelloSoapBindingStub.java
    6.編寫客戶端程序,編譯并執行
    public?class?SayHelloClient?{
    ????public?static?void?main(String[]?args)?{
    ????????try?{
    ????????????
    ????????????SayHelloService?service?=?new?client.
    ???????????????????????????????????????????????SayHelloServiceLocator();
    ????????????client.SayHello_PortType?client?=?service.getSayHello();
    ????????????String?retValue=client.getName("zhangsan");
    ????????????System.out.println(retValue);

    ????????????
    ????????}?catch?(Exception?e)?{
    ????????????System.err.println("Execution?failed.?Exception:?"?+?e);
    ????????}
    ????}
    }
    posted on 2006-03-30 12:54 SIMONE 閱讀(878) 評論(0)  編輯  收藏 所屬分類: AXIS
    主站蜘蛛池模板: 亚洲欧洲精品成人久久曰影片| 精品一区二区三区无码免费视频 | 欧洲黑大粗无码免费| 91嫩草私人成人亚洲影院| 国产成人免费ā片在线观看老同学 | 亚洲第一区香蕉_国产a| 国产成人免费AV在线播放| 亚洲无线码在线一区观看| 中文字幕版免费电影网站| 亚洲精品无码久久久久sm| 国产在线精品免费aaa片| 亚洲色图在线观看| 亚洲精品视频免费看| 亚洲成A人片在线播放器| 美女被免费视频网站a国产| 豆国产96在线|亚洲| 亚洲男人的天堂在线va拉文| 中文字幕在线视频免费观看| 亚洲午夜精品一区二区 | 免费爱爱的视频太爽了| 亚洲av无码av在线播放| 亚洲精品无码久久毛片| 嫩草影院在线播放www免费观看| 久久精品亚洲综合专区| 国产免费看JIZZ视频| 亚洲国产成人AV网站| 国产精品亚洲精品日韩已满| 8x8×在线永久免费视频| 亚洲熟妇AV一区二区三区浪潮 | 野花香高清在线观看视频播放免费| 亚洲第一区香蕉_国产a| 成人免费毛片内射美女APP| 黄网站在线播放视频免费观看 | 亚洲一区二区三区免费在线观看 | 久久亚洲sm情趣捆绑调教| 成人毛片手机版免费看| 一边摸一边桶一边脱免费视频| 亚洲影院在线观看| 在线观看免费国产视频| 免费的全黄一级录像带| 无码一区二区三区亚洲人妻 |