AXIS2 WebServices开发实践(一)

 

1、概述

AXIS2 是Apache SOAP协议的实现。基于TCP/IP协议使用XML实现远程数据通信的一种技术,分为Server与Client。

OS:Windows 7 旗舰版;Java JVM:jdk1.5.0_08;IDE:Eclipse v3.5。

 

2、下载AXIS2

2.1、地址

http://www.apache.org/dist/ws/axis2/1_5_1/

2.2、文件

axis2-1.5.1-bin.zip    // 应用开发只需要下载此文件即可

axis2-1.5.1-docs.zip // 开发中参考文档,推荐下载

axis2-1.5.1-war.zip   // 部署到tomcat,推荐下载

axis2-1.5.1-src.zip    // 源码,推荐下载

axis2-1.5.1.pom      // mavenpom,非必须

如下图所示:

3、设置eclipse axis2 runtime

3.1、解压

解压“axis2-1.5.1-bin.zip”文件到指定目录,例:“d:\develop\java\ws\axis2-1.5.1”;

3.2、eclipse中配置axis2环境

打开“eclipse >>Windows >> Preferences”窗口,选择“Web Services >> Axis2 Preferences”标签页,设置“Axis2Runtime >> Axis2 Runtime Location:”为上面的解压目录。如果显示“Axis2runtime loaded successfully”字样则说明配置成功。如下图所示:

4、创建web service

4.1、创建web工程axis2test

选择“File >> new>> Dynamic Web Project”创建WEB工程;选中工程并点击右键在弹出的快捷菜单中选择“Properties”,在打开的窗口中选择“Project Facets”并在右边的复选框选择“Axis2 Web Services”下的“Axis2 Web Services Core”与“Axis2 Web ServicesExtensions”。如下图所示:

4.2、复制源代码文件到工程中

         复制“org.apache.axis2.webapp”包下的所有文件到src下。

4.3、创建Hello.java

public class Hello {

        public String say(){

           return"昨夜星晨昨夜风";

        }

}

4.4、直接发布Hello为Web service

(1)、选中“Hello.java”点击右键在弹出的快捷菜单中点击“Web Services >> Create Web service”,在弹出的对话框中,选中“Publish the Web service”复选框。

        

(2)、点击“Server:Tomat 6.0”或“Webservice runtime:Apache Axis”连接,在弹出的“Service Deployment Configuration”窗口中,选中“Tomcat v6.0Server at localhost”与“ApacheAxis2”,并点击OK,并点击“Next”。

        

(3)、在之后弹出的窗口中不做更改直接一路“Next”直到最后点击“Finish”即可,其中需要启动tomcat,启动它即可。

        

        

4.5、验证发布结果

4.5.1、查看服务

输入:http://192.168.100.57:8080/axis2test/services/listServices

返回:

        

4.5.2、调用服务

输入:http://192.168.100.57:8080/axis2test/services/Hello/say

返回:

<ns:sayResponsexmlns:ns="http://test.axis2.evensoft.org.cn">

           <ns:return>昨夜星晨昨夜风</ns:return>

  </ns:sayResponse>

 

4.5.3、查看服务wsdl

输入:http://192.168.100.57:8080/axis2test/services/Hello?wsdl

返回:

<?xmlversion="1.0"encoding="UTF8"?>

<wsdl:definitionsxmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"

    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"xmlns:ns1="http://org.apache.axis2/xsd"

    xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"xmlns:ns="http://test.axis2.evensoft.org.cn"

    xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

    targetNamespace="http://test.axis2.evensoft.org.cn">

    <wsdl:documentation>Please Type yourservice description here

    </wsdl:documentation>

    <wsdl:types>

       <xs:schemaattributeFormDefault="qualified"

           elementFormDefault="qualified"targetNamespace="http://test.axis2.evensoft.org.cn">

           <xs:elementname="sayResponse">

              <xs:complexType>

                  <xs:sequence>

                     <xs:elementminOccurs&

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值