CoffeeTree
IT 男人's Blog helloheyongjin@sina.com
你大娘已经不是你从前的大娘,你大爷依旧是你大爷
 

构建Webservice工程
下载附件/Files/heyongjin/webservice.doc

1、 创建一个工程

2、 导入Jar包

3、 在部署描述符web.xml中配置AxisServlet

    <servlet>

        <servlet-name>AxisServlet</servlet-name>

        <display-name>Apache-Axis Servlet</display-name>

        <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>

    </servlet>

    <servlet-mapping>

        <servlet-name>AxisServlet</servlet-name>

        <url-pattern>/servlet/AxisServlet</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

        <servlet-name>AxisServlet</servlet-name>

        <url-pattern>*.jws</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

        <servlet-name>AxisServlet</servlet-name>

        <url-pattern>/services/*</url-pattern>

    </servlet-mapping>

4、 编写服务端程序

package com.axis;

publicclass ServerAxis {

    public String remoteMethod(String message) {

        return"Your Message is : " + message;

    }

}

5、 编写客户端测试程序

package com.axis;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

publicclass ClientAxis {

    publicstaticvoid main(String []args){

       

        try {

            String url = "http://127.0.0.1:9090/Webservice/services/ServerAxisWSDD";

            Service service = new Service();

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

            call.setTargetEndpointAddress(url);

            call.setOperationName(new QName(url,"remoteMethod"));

            String result = (String) call.invoke(new Object[]{"Hello AXIS!"});

            System.out.println(result);

        } catch (ServiceException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        } catch (RemoteException e) {

            // TODO: handle exception

        }

    }

}

6、 编写发布文件WEB-INF"deploy.wsdd

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

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

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

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

        <parameter name="scope" value="request"/>

    </service>

</deployment>

7、  发布AXIS

首先将工程发布到tomcat,启动应用,通过windows控制台进入%TOMCAT%"webapps"ProjName"WEB-INF目录下键入如下命令:

Java –Djava.ext.dirs=lib org.apache.axis.client.AdminClient –l http://localhost:8080/ ProjName/services/ServerAxisWSDD deploy.wsdd

 

posted on 2010-04-23 19:11 何永进 阅读(2735) 评论(0)  编辑  收藏 所属分类: Java Web

只有注册用户登录后才能发表评论。


网站导航: