加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

axis2 webservice

发布时间:2020-12-17 00:20:08 所属栏目:安全 来源:网络整理
导读:一 .准备: ???????????? 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下发布,测试是否成功?

一 .准备:

???????????? 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-INFservices 文件夹,并创建AxisServiceMETA-INFservices.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.csdn.net/detail/meililiuwei/5454911??? 上传的资源中有所有需要的jar包

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读