1.建立工程:名称为AxisWebService,导入spring,axis所需的包
(博客中有一篇文章讲解了axis的配置问题)
2.建立接口类
IUserService 代码如下:
package com.gis.service;
public interface IUserService {
String login(String name) ;
}
3.建立接口实现类
UserService 代码如下:
package com.gis.service.impl;
import com.gis.service.IUserService;
public class UserService implements IUserService {
public String login(String name) {
if("liqi".equals(name))
{
return "success" ;
}
else
{
return "fault" ;
}
}
}
4.建立继承ServletEndpointSupport并实现IUserService接口的类
UserWebService,代码如下
package com.gis.service.webservice;
import javax.xml.rpc.ServiceException;
import org.springframework.remoting.jaxrpc.ServletEndpointSupport;
import com.gis.service.IUserService;
public class UserWebService extends ServletEndpointSupport implements
IUserService {
private IUserService userService ;
protected void onInit() throws ServiceException
{
userService = (IUserService)this.getWebApplicationContext().getBean("userService") ;
}
public String login(String name) {
return userService.login(name) ;
}
}
5.配置Web工程的web.xml文件,
文件路径为WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>axis</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>axis</servlet-name>
<url-pattern>/webservices/*</url-pattern>
</servlet-mapping>
</web-app>
6.配置bean,即添加
spring的配置文件applicationContext.xml,路径为WEB-INF/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="userService"
class="com.gis.service.impl.UserService">
</bean>
</beans>
7.编写axis使用的WSDD文件,
名称为server-config.wsdd,路径为WEB-INF/server-config.wsdd
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler name="URLMapper"
type="java:org.apache.axis.handlers.http.URLMapper" />
<!-- 系统服务 -->
<service name="AdminService" provider="java:MSG">
<parameter name="allowedMethods" value="AdminService" />
<parameter name="enableRemoteAdmin" value="false" />
<parameter name="className" value="org.apache.axis.utils.Admin" />
<namespace>http://xml.apache.org/axis/wsdd/</namespace>
</service>
<service name="Version" provider="java:RPC">
<parameter name="allowedMethods" value="getVersion" />
<parameter name="className" value="org.apache.axis.Version" />
</service>
<!-- 自定义服务 -->
<service name="userWebService" provider="java:RPC">
<parameter name="className"
value="com.gis.service.webservice.UserWebService" />
<parameter name="allowedMethods" value="*" />
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper" />
</requestFlow>
</transport>
</deployment>
8.浏览器测试wsdl信息
在浏览器中输入http://localhost:8888/AxisWebService/webservices/userWebService?wsdl测试是否返回webservice描述信息
9.代码测试调用并验证返回,编写测试类
import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import org.apache.axis.client.Service;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
String wsdlUrl = "http://localhost:8888/AxisWebService/webservices/userWebService?wsdl";
String nameSpaceUri = "http://localhost:8888/AxisWebService/webservices/userWebService";
// 创建调用对象
Service service = new Service();
Call call = null;
call = (Call) service.createCall();
// 调用sayHello
System.out.println(">>>getMessage");
call.setOperationName(new QName(nameSpaceUri, "login"));
call.setTargetEndpointAddress(wsdlUrl);
String ret = (String) call.invoke(new Object[] {"liqi"});
System.out.println("return value is " + ret);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
借鉴网上的资源,弄了一个SpringBoot开发WebService之Axis示例。
简单例子:axis2整合spring发布webservice,以及session的管理
spring+axis集成webservice
spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码
Spring集成axis2实现webservice所用到的Jar包,将所有的包放到项目的LIB目录下面
Spring+axis2开发webservice[整理].pdf
一个spring+axis开发webservice的完整例子,还配有jdom解析xml
Axis2WebService与Spring的整合
NULL 博文链接:https://laochake.iteye.com/blog/445833
通过axis2与spring进行集成,发布webservice服务,
Axis的简单准备 Axis的入门实例 Axis复杂对象类型的WebService Axis的辅助工具发布、调用WebService Axis WebService会话Session的管理 ... Axis使用SoapMonitor监视WebService的请求和响应信息
Axis 的简单准备 Axis 的入门实例 Axis 复杂对象类型的WebService Axis 的辅助工具发布、调用WebService Axis WebService 会话Session 的管理 ...Axis 使用SoapMonitar 监视WebService 的请求和响应信息
Axis2与Spring整合发布多个WebService,项目使用Maven管理。
axis2+spring2.5整合(webservice)
axis2 webservice 样例 使用的是spring axis2 的整合。
lib包中包含所有axis2+spring所需要的jar包
首先,该工程实现了spring MVC、mybatis、axis webservice功能 其次,这个工程很简单,只做了最简单的功能实现 再次,数据库要自己准备 最后,该工程里的src目录下,有一个readme.txt,请下载者仔细阅读,里面有...
Spring+Axis2+Maven搭建WebService服务端demo测试用例
axis2+Spring提供WebService服务,有调用方法类。