WebService------AXIS

 

WebService----AXIS

一、 下载

下载 1.4 http://apache.etoak.com/ws/axis/1_4/axis-bin-1_4.zip

如已失效请参见 http://ws.apache.org/axis/

二、 安装

解压 axis-bin-1_4.zip ,比如我解压在了 E:\axis1\axis-bin-1_4

Tomcat

修改 $TOMCAT_HOME/conf/server.xml

<Host>….</Host> 中添加以下行

<Context docBase="E:\\axis1\\axis-bin-1_4\\axis-1_4\\webapps\\axis" path="">

</Context>

( 建议放在 </Host> 上面,目录按照实际情况修改 )

 

Resin:

( resin 下要先修改 E:\axis1\axis-bin-1_4\axis-1_4\webapps\axis\WEB-INF\web.xml

<welcome-file-list id="WelcomeFileList"> 改为 <welcome-file-list>)

$RESIN_HOME/conf 下复制 resin.conf resin-axis.conf ,修改此文件

<Host>….</Host>

<web-app id="/" document-directory="E:\\axis1\\axis-bin-1_4\\axis-1_4\\webapps\\axis"/>

( 目录按照实际情况修改 )

$RESIN_HOME/bin 下复制 httpd.exe httpd-axis.exe ,修改文件属性

目标项改为:

E:\resin3025\httpd.exe -conf E:\resin3025\conf\resin-axis.conf-Xmx128m -Xms128m

启动后看到如下,则正常


三、 建立服务

1. 新建 web 项目 axis_server

拷贝部署成功的 axis 下的 lib 目录和 web.xml 文件到新建项目的 WEB-INF

仿照 resin 上部署服务的过程,

$RESIN_HOME/conf 下复制 resin.conf resin-axis_server.conf ,修改此文件

<Host>….</Host>

<web-app id="/"

document-directory="E:\\eclipse-lomboz-3.2\\workspace\\axis_server\\WebContent"/>

( 目录按照实际情况修改 )

$RESIN_HOME/bin 下复制 httpd.exe httpd-axis_server.exe ,修改文件属性

目标项改为:

E:\resin3025\httpd.exe -conf E:\resin3025\conf\resin-axis_server.conf-Xmx128m -Xms128m 启动项目

2 服务端代码

 

AxisServerDemo.java

package com.axis.server;

 

import java.rmi.Remote;

import java.rmi.RemoteException;

 

public class AxisServerDemo implements Remote{

 

      public int getMessage(String doc) throws RemoteException{

          return AxisServerDemoImpl.getMessage ();

      }

}

AxisServerDemoImpl.java

package com.axis.server;

 

import java.rmi.RemoteException;

 

public class AxisServerDemoImpl {

 

      public static int getMessage() throws RemoteException{

          return 0;

      }

}
 

 

3.wsdd 文件

发布服务文件 deploy.wsdd

 

< deployment xmlns = "http://xml.apache.org/axis/wsdd/"

            xmlns:java = "http://xml.apache.org/axis/wsdd/providers/java" >

 

  < service name = "AxisServerDemo" provider = "java:RPC" >

  < parameter name = "className" value = "com.axis.server.AxisServerDemo" />

  < parameter name = "allowedMethods" value = "*" />

  </ service >

 

</ deployment >
 

 

        卸载服务文件 undeploy.wsdd

       

< undeployment xmlns = "http://xml.apache.org/axis/wsdd/" >

        < service name = "AxisServerDemo" />

</ undeployment > 
 

4. 发布服务

进到项目的 WEB-INF 下执行如图操作


将会在 WEB-INF 下生成以下文件

server-config.wsdd 文件

attachments 目录

        5. 访问

       

6. 生成客户端代码


 

7. 测试服务

 

 

 

package  com.axis.test;

 

import com.axis.client.AxisServerDemoService;

import com.axis.client.AxisServerDemoServiceLocator;

import com.axis.client.AxisServerDemo_PortType;

 

public class TestClient{

 

    public static void AxisServerDemoClient() throws Exception {

 

    AxisServerDemoService service = new AxisServerDemoServiceLocator();

 

    AxisServerDemo_PortType client = service.getAxisServerDemo() ;

 

        int ret = client.getMessage( "abc" );

 

        System. out .println(ret);

 

    }

   

    public static void main(String args[]){

    try {

          AxisServerDemoClient ();

       } catch (Exception e) {

          // TODO Auto-generated catch block

          e.printStackTrace();

       }

    }

}

 

word格式说明及项目源码见附件

 

你可能感兴趣的:(java,apache,tomcat,Web,webservice)