一.axis2服务端编写
1.1 web.xml配置
在web.xml中添加如下配置项:
<!-- 注册axis2的servlet -->
<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>
1.2 java接口与接口实现代码编写
接口:
package com.hsinghsu.www;
public interface AxisService
{
public String login(String name, String password);
}
接口实现:
package com.hsinghsu.www;
public class AxisServiceImpl implements AxisService
{
public String login(String name, String password)
{
if (null == name || null == password)
{
return "error|参数错误";
}
else
{
return "succss|good";
}
}
}
1.3 applicationContext.xml文件配置
在applicationContext.xml中添加如下配置文件:
<bean id="axisService" class="com.hsinghsu.www.AxisServiceImpl"></bean>
1.4 services.xml文件配置
在WebContent或WebRoot目录下,新建目录services/serviceXML/META-INF/services.xml文件【其中serviceXML这个目录名称随意,其余的不能修改】。
<?xml version="1.0" encoding="UTF-8"?>
<serviceGroup>
<service name="testAsixService">
<description>对外提供soap接口</description>
<!-- 通过ServiceObjectSupplier参数指定SpringServletContextObjectSupplier类来获得Spring的ApplicationContext对象 -->
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
</parameter>
<!-- 接口类 -->
<parameter name="ServiceClass">
com.hsinghsu.www.AxisService
</parameter>
<!-- 这个要与spring的配置文件里的bean一样 -->
<parameter name="SpringBeanName">axisService</parameter>
<!-- <messageReceivers>节点用于设置处理WebService方法的处理器 in-out有返回值 ;in-only没有返回值 -->
<messageReceivers>
<messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
</service>
</serviceGroup>
1.5 测试
在浏览器中输入:http://127.0.0.1:80/application/services/testAsixService?wsdl 【注:application为该项目应用名称,services为在web.xml中配置的路径,testAsixService为在services.xml中配置的service名称】
结果如下:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://www.hsinghsu.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://www.hsinghsu
SOAP协议服务端编写(Axis2 XFire)
最新推荐文章于 2021-02-12 15:09:46 发布
本文介绍了如何使用Axis2和XFire创建SOAP服务端。首先,展示了Axis2的配置,包括web.xml、接口和实现、applicationContext.xml以及services.xml的设置。接着,详细解释了XFire的配置和接口实现。最后,文章提供了客户端测试的简单示例,演示了如何调用SOAP服务。
摘要由CSDN通过智能技术生成