学习了一段时间的webservice,今天有空,稍微总结一下。
首先我们选的是axis2-1.4 +myeclipse6.5+tomcat 6.0,大家肯定不陌生了。我们以前都是把从官网上下载的war包考到tomcat的webapps下,但是现在我们自己建一个web项目
1、首先建立一个web工程,名字叫WebService,
2、把相应的axis2的jar文件考到WEB-INF的lib下
3、
在项目的WebRoot下的目录结构要和以前用war包是的目录结构一样(否则可能就要报 错了)
目录结构如图所示:
4、在src下建立package sample.service
5、建立提供服务的接口
package sample.service;
/**
* 定义服务接口
* @author 11111
*
*/
public interface ServiceServer {
//定义服务方法
public String sayHello(String name);
}
实现类:
package sample.service;
public class ServiceServerImpl implements ServiceServer {
public String sayHello(String name) {
return "hello"+name;
}
}
6、在src下建立applicationContext.xml文件
配置如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="SayHelloService" class="sample.service.ServiceServerImpl">
</bean>
</beans>
7、在WebRoor/WEB-INF/services/目录下建立目录sampleService(这个名字可以随便取)
然后建立在其下META-INF目录,然后再在其目录下建立services.xml
目录结构如下
services.xml的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<service name="HelloWorld">
<description>web service</description>
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
</parameter>
<parameter name="SpringBeanName">SayHelloService</parameter>
//SpringBeanName名字是固定的不能改
//SayHelloService是spring中注册的实现类的id(这个大家肯定很清楚了)
<operation name="sayHello">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>
8、现在要配置一下web.xml了
内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>AxisServlet</servlet-name>
//注册axis2的servlet
<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>
//加载spring的配置文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
//增加spring监听器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
9、启动tomcat 在浏览器中输入
http://localhost:8080/WebService/services/listServices
可以看到一下内容说明我们的服务已经发布成功了
访问
http://localhost:8080/WebService/services/HelloWorld?wsdl
可以查看wsdl
待会就是访问我们的服务了(用axis2 的eclipse 插件自动生成客户端),
如果有问题可以加群 : 84242283(webservice交流学习)
- 大小: 29.8 KB
- 大小: 11.6 KB
- 大小: 69.5 KB
分享到:
相关推荐
<artifactId>axis2</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>1.6.2</...
简单例子:axis2整合spring发布webservice,以及session的管理
spring,cxf,restful发布webservice传递复杂对象,例如List,Map,List<Map>
Axis2 Webservice端例子Axis2 Webservice端例子
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-...
spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码
本案例实现使用Axis2生成.arr包发布WebService服务,并使用Axis2生成客户端代码方式调用WebService
spring+axis集成webservice
今天特意将项目中用Axis2集成SSH实现WebService的过程记录下来,一方面做一下笔记,另一方面,方便广大码农朋友,希望能跟大家交流学习。 本文介绍用Axis2集成SSH搭建WebService。会达到的效果: 1.按照传统我们用...
axis2和spring结合发布WebService源码
WebService大讲堂之Axis2 WebService大讲堂之Axis2 WebService大讲堂之Axis2 WebService大讲堂之Axis2 WebService大讲堂之Axis2 WebService大讲堂之Axis2
axis2+Spring提供WebService服务,有调用方法类。
Spring集成axis2实现webservice所用到的Jar包,将所有的包放到项目的LIB目录下面
axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例
Axis2与Spring整合发布多个WebService,项目使用Maven管理。
说明:<br>由于上传速度的问题例子面没有加包,请下载后自己将Axis 1.4的lib包放到你的工程里头就可以了。<br>当然可以调用任何 wsdl地址。只要是webservice<br>这里是比较流行的。<br>这里有2个测试地址。<br>(1)...
借鉴网上的资源,弄了一个SpringBoot开发WebService之Axis示例。
CXF WebService整合Spring示例工程代码demo可以直接导入eclipse。参照网页http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html 完成的webService服务提供。 大致步骤: 1.引入cxf和其他需要的jar包,(本...
通过axis2与spring进行集成,发布webservice服务,
C#编程经验技巧宝典源代码,目录如下:<br>第1章 开发环境 1<br><br>1.1 Visual Studio开发环境安装与配置 2<br><br>0001 安装Visual Studio 2005开发环境须知 2<br><br>0002 配置合适的Visual Studio 2005...