`
daniel_tu
  • 浏览: 182702 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

使用Axis开发WebService

阅读更多

一、Axis安装
1.测试环境
    JDK 1.5
    Servlet Container: Tomcat 5.5
2.下载地址:
http://ws.apache.org/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.设置classpath编写setEnv.bat:


set AXIS_HOME=$AXIS_UNZIP_HOME
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


二.使用axis支持web service的部署和开发,最主要有两种方式:

(一)。Dynamic Invocation Interface ( DII)
1.编写服务端程序HelloClient

public class HelloClient {
 ublic 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();
}

}

}

5.运行TestHelloClient测试;

(二)。 Stubs方式
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.";
serviceHandler.setOption(
"accesses"
, numAccesses);

System.out.println(result);
}
 catch (Exception e) {
throw
 AxisFault.makeFault;
}

}

}

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>

4.将编译后的文件拷贝到AXIS_HOME/WEB-INF/classes下,如:D:\tomcat\webapps\axis\WEB-INF\classes

5.发布服务:
java org.apache.axis.client.AdminClient -h localhost -p 8080 -s /axis/servlet/AxisServlet deploy.wsdd

命令参数为:

The following Options are available:

        
-l<url>
         sets the AxisServlet URL
        
-h<
hostName     sets the AxisServlet host
        
-p<portNumber>
  sets the AxisServlet port
        
-s<servletPath>
 sets the path to the AxisServlet
        
-f<fileName>
    specifies that a simple file protocol should be used
        
-u<username>
    sets the username
        
-w<password>
    sets the password
        
-d              sets the debug flag (for instance, -
ddd would set it to
3
)
        
-t<name>
        sets the transport chain touse

Commands:

        list            will list the currently deployed services
        quit            will send a quit message to SimpleAxisServer
        passwd          value changes the admin password

Deployment Descriptor files:

<deployment-descriptor-files>
 deploys or undeploys Axis components and
web services described in these files

If 
-l or ---
s are not set, the AdminClient will invoke
http:
//localhost:8080/axis/servlet/AxisServlet

6.生成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

7.编写客户端程序,编译并执行

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);
}

}

}
 

8.开发自己的WEB应用程序的web service ,需要在描述文件WEB-INF/web.xml文件中添加:

<listener>
        
<listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
    
</listener>
    
  
<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>
    
<servlet-name>AdminServlet</servlet-name>
    
<display-name>Axis Admin Servlet</display-name>
    
<servlet-class>
        org.apache.axis.transport.http.AdminServlet
    
</servlet-class>
    
<load-on-startup>100</load-on-startup>
  
</servlet>

  
<servlet>
    
<servlet-name>SOAPMonitorService</servlet-name>
    
<display-name>SOAPMonitorService</display-name>
    
<servlet-class>
        org.apache.axis.monitor.SOAPMonitorService
    
</servlet-class>
    
<init-param>
      
<param-name>SOAPMonitorPort</param-name>
      
<param-value>5001</param-value>
    
</init-param>
    
<load-on-startup>100</load-on-startup>
  
</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>
http://phoenixup.cnblo
分享到:
评论

相关推荐

    使用axis开发webservice使用的jar包

    本篇文章将深入探讨如何使用Axis开发Web服务,并详细解释相关jar包的作用。 首先,让我们了解Web服务的基本概念。Web服务是一种通过互联网进行通信的应用程序,遵循W3C制定的SOAP(Simple Object Access Protocol)...

    java使用axis开发webservice服务端和客户端简单例子

    访问地址: http://127.0.0.1:8080/axis/services

    SpringBoot开发WebService之Axis示例

    在本文中,我们将深入探讨如何使用SpringBoot框架开发基于Axis的Web服务。SpringBoot以其便捷的启动和配置方式,已经成为Java开发中的首选框架之一。而 Axis 是一个流行的Apache项目,用于创建和部署Web服务,它提供...

    axis+webservice学习教程

    ### 使用AXIS开发WebService教程详解 #### 一、前言 本文将详细介绍如何利用Apache Axis框架来开发WebService。Apache Axis是Apache软件基金会的一个开源项目,它提供了强大的工具集用于实现和部署基于SOAP协议的...

    axis 开发webservice经典入门例子

    标题 "axis 开发webservice经典入门例子" 指向的是使用Apache Axis工具来创建和使用Web服务的基本教程。Apache Axis是开源的Java框架,它允许开发者轻松地在Java应用程序中构建和部署Web服务。本教程可能是为了帮助...

    axis2webservice接口例子

    标题中的“axis2webservice接口例子”指的是使用Apache Axis2框架创建的一个Web服务接口实例。Apache Axis2是Java平台上的一款强大的Web服务开发工具,它提供了高效、灵活且可扩展的环境来构建和部署Web服务。这个...

    axis开发webservice客户端

    标题中的“axis开发webservice客户端”指的是使用Apache Axis框架创建并使用Web服务客户端的过程。Apache Axis是Java平台上的一个开源工具,它简化了SOAP(Simple Object Access Protocol)Web服务的开发,包括...

    Java开发WebService实例

    使用Axis开发WebService有两种主要方式:DII(Dynamic Invocation Interface)和Stubs。其中,DII方式更为灵活,适用于动态生成WebService接口的情况。 1. **编写Java类**:创建一个简单的Java类,例如`HelloWorld`...

    使用Axis+Eclipse开发webservice

    使用 Axis 和 Eclipse 开发 Web Service,可以简化开发流程,提高效率。Axis 是 Apache 维护的开源工具,它提供了生成服务端和客户端代码的能力,而 Eclipse 则提供了一个集成的开发环境,方便创建、调试和部署 Web ...

    Axis2WebService 源码

    Axis2 WebService是一个开源的、基于Java的Web服务框架,由Apache软件基金会开发。它提供了构建和部署Web服务以及处理SOAP消息的强大工具。这个源码包可能是为了帮助开发者深入理解Axis2的工作原理,或者用于自定义...

    基于axis2实现的webservice简单实现(客户端+服务端)。

    【标题】中的“基于axis2实现的webservice简单实现(客户端+服务端)”表明了本文将探讨如何使用Apache Axis2框架来创建和消费Web服务。Apache Axis2是Apache软件基金会开发的一个Web服务引擎,它提供了高效且灵活的...

    利用axis开发webservice使用的jar包

    本文将详细介绍如何利用Axis开发Web服务,并探讨其使用的jar包。 首先,我们要理解Axis的核心功能。Axis提供了一套完整的Java API,使得开发者能够方便地构建Web服务客户端和服务器端。它支持SOAP(简单对象访问...

    axis 发布webservice的步骤

    标题中的“axis发布webservice的步骤”涉及到的是在Java环境中使用Apache Axis库创建并部署Web服务的过程。Apache Axis是开源的Web服务工具包,它允许开发者通过简单的API将Java类暴露为Web服务,或者调用远程Web...

    eclipse+AXIS开发webservice.doc

    本文档主要介绍了如何使用Eclipse和AXIS框架开发和发布Web服务,以及进行客户端测试。以下是详细步骤和关键知识点: 1. **Eclipse插件安装**: - Eclipse提供了Web服务开发的插件,可以从官方网站下载WTP(Web ...

    AXIS WebService

    ### 使用AXIS开发WebService知识点详解 #### 一、AXIS简介 AXIS是Apache软件基金会下的一个开源项目,主要用于在Java环境下实现Web服务。它基于SOAP协议,支持XML数据格式,能够帮助开发者轻松构建和发布Web服务。...

    axis+webservice教程.doc

    ### 使用AXIS开发WebService教程——如何发布自己的WebService #### 一、开发环境搭建与配置 在开始本教程之前,我们先来了解一下作者所使用的开发环境: - **JDK版本**:1.4.2 - **IDE**:MyEclipse 6.0 - **Web...

    Axis开发WebService 指南

    本文将深入探讨如何利用Axis开发WebService,以及相关的技术要点。 首先,了解WebService的基础概念是至关重要的。WebService是一种基于开放标准(如XML、WSDL和SOAP)的互联网应用程序,它能够跨平台、跨语言地...

    Axis和WebService配置使用之Hello

    标题中的“Axis和WebService配置使用之Hello”表明我们将探讨如何在Java环境中使用Axis库来创建和使用Web服务,实现一个简单的“Hello World”示例。 Axis是一个开源的Java SOAP(简单对象访问协议)工具包,它允许...

Global site tag (gtag.js) - Google Analytics