axis2 webservice

一 .准备:

             1. 首先下载axis2-1.6.2 需要axis2-1.6.2-bin.zip ,axis2-1.6.2-war.zip 文件 。 下载地址http://axis.apache.org/axis2/java/core/download.cgi

             2. 解压下载的war 包,并将内部的war包在tomcat下发布,测试是否成功    http://localhost:8080/axis2/    点击Service会进入Service列表页面,

                   当前只有一个Version服务。http://localhost:8080/axis2/services/Version?wsdl

             3. 下载 axis2-eclipse-service-plugin-1.6.2.zip,axis2-eclipse-codegen-plugin-1.6.2.zip  解压后将plugins 复制到eclipse的plugins,

                    高版本的eclipse需要复制到dropins 文件夹下  下载地址   http://axis.apache.org/axis2/java/core/tools/index.html    

                                        

                                      myeclipse 8.5  会报缺少jar 的错误,网上找到需要的jar ,放在dropins 文件夹下,并删除configuration 下的update文件夹

 

二 .部署

                 1.  新建java web project 工程,并将 axis2 的war包中的 lib 中的文件 ,jar包 拷贝到项目的lib中 ,并加入引用

                      将   axis2的war包中的WEB-INF 下  conf  内容 复制到 项目  WEB-INF 中的conf 下

                      将   axis2 的war包中的 WEB-INF 下 modules 文件夹复制到 项目 WEB-INF 中的 modules  下

                 2. 修改 web.xml ,添加 如下代码

                            <servlet>
                                    <servlet-name>AxisServlet</servlet-name>
                                    <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
                                    <load-on-startup>1</load-on-startup>
                           </servlet>
                          <servlet-mapping>
                                     <servlet-name>AxisServlet</servlet-name>
                                    <url-pattern>/services/*</url-pattern>
                          </servlet-mapping>

                3. 新增 com.webservice.WebserviceTest.java,

                           public String showName(String name) {
                                     System.out.println(new SimpleDateFormat("yyyyMMddHHmmssSSS") .format(new Date())+"service showname");
                                     return  "hello"+name;
                            }

                4. 新增 WEB-INF\services 文件夹,并创建\AxisService\META-INF\services.xml   内容如下

<service name="AxisService">
<description>AxisService</description>
<parameter name="ServiceClass">com.webservice.WebserviceTest</parameter>
<operation name="showName">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>

               5.启动tomcat,http://localhost:8080/项目名称/services/AxisService?wsdl  测试

三 .调用

             1.  生成 插件 

                               在eclipse 中,选择 new ---- other ---- Axis2 Code Generator ,点击next

                                   

                     勾选Generate Java source code from a WSDL file,点击Next;

                     输入 服务路径   http://localhost:8080/项目名称/services/AxisService?wsdl    点击next 

                                     若 输入服务路径错误或服务未启动则出现

                       继续next ,出现

                                                 
                                   提示:All operations completed successfully! 生成成功。

 

              2.   新建java 项目 ,并  将  bin.zip中的 lib 下的所有jar 包复制到 项目下的lib 包中,并加入引用

             3.   将生成的插件复制到项目中

             4.   创建  test.TestWs.java

public class TestWs {
public static void main(String[] args) throws RemoteException {
	AxisServiceStub stub = new AxisServiceStub();
	//传递AxisServiceStub.ShowName对象,相关参数在这边赋值。
	ShowName command = new ShowName();
	command.setName("Hello!");
	//取得返回值
	String name = stub.showName(command).get_return();
	System.out.println(new SimpleDateFormat("yyyyMMddHHmmssSSS") .format(new Date()));
	System.out.println(name+"method  showname");

}
}

                    下来测试,就行

     http://download.youkuaiyun.com/detail/meililiuwei/5454911    上传的资源中有所有需要的jar包


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值