今天和大家分享 使用 web方式发布 webService 服务端、客户端

1.首先创建 一个web工程(增加Maven依赖)

2.增加Maven依赖包,如下:

         <!-- spring core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.5.5</version>
</dependency> <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
</dependency> <dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<type>pom</type>
</dependency> <dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency> <dependency>
<groupId>xfire</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3</version>
</dependency> <dependency>
<groupId>xfire</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency> <dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.2.3</version>
</dependency>

3. 编写HelloWorld 接口类 代码如下:

 package net.cc.service;

 import javax.jws.WebParam;
import javax.jws.WebService; /**
* @author test
* @create 2013-11-26下午10:21:13
*/
@WebService
public interface HelloWorld { String sayHello(@WebParam(name = "userName") String userName); }

说明:

@webService    说明这是一个webService

@webParam     说明参数名称


4. 编写实现类 如下:

 package net.cc.service;

 import javax.jws.WebParam;
import javax.jws.WebService; /**
* @author test
* @create 2013-11-26下午10:22:53
*/
@WebService(serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld { @Override
public String sayHello(@WebParam(name = "userName") String userName) {
// TODO Auto-generated method stub
System.out.println("客户端提交信息: " + userName);
return "say Hello " + userName;
}
}

说明:

@webService(serviceName = “HelloWorld”)    让Apache cxf知道是哪个接口来创建的WSDL

5. 编写spring 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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:endpoint id="ProjectManager" implementor="net.cc.service.HelloWorldImpl"
address="http://192.168.1.105:7890/HelloWorld" /> </beans>

说明:

implementor  表示 实现类 路径

address 表示需要发布的wsdl地址

 

6.编写 myListener 类 如下:

 package net.cc.servlet;

 import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* @author test
* @create 2013-11-26下午10:41:53
*/
public class myListener implements ServletContextListener { @Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub } @Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println("启动Tomcat...");
ClassPathXmlApplicationContext act = new ClassPathXmlApplicationContext(
"/net/cc/service/spring-beans.xml"); } }

说明:

实现 ServletContextListener 目的是为了在Tomcat启动时自动加载

使用 ClassPathXmlApplicationContext 去加载刚才写的 spring-beans.xml 文件

7. 在当前项目中web.xml文件  增加如下代码:

     <listener>
<listener-class>net.cc.servlet.myListener</listener-class>
</listener>

说明:

实现 ServletContextListener 接口的类路径

8 tomcat 启动截图:

 

9  访问web界面 截图:

完成。。。。。。。。。。

Maven搭建webService (二) 创建服务端---使用web方式发布服务的更多相关文章

  1. Maven搭建webService (一) 创建服务端---使用main函数发布服务

    今天和大家分享下 使用maven 搭建 webService 服务端: 首先需要在你的IDE中集成Maven.集成办法此处略....... 1.创建一个web工程. 2.在pom文件中增加以下依赖: ...

  2. Maven搭建webService (三) 创建客户端---使用Apache CXF方式实现

    package test; import net.cc.web.server.HelloWorld; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean ...

  3. maven搭建webservice apache cxf实现

    用 web方式发布 webService 服务端.客户端 一.服务器端搭建 1.首先创建 一个web工程(增加Maven依赖) 2.增加Maven依赖包,如下: <project xmlns=& ...

  4. 搭建基于.NetFrameWork的私有nuget服务端及打包项目发布上传

    一.私有Nuget服务端搭建 1.创建一个.NetFramework web项目 2.在nuget管理中 安装 nuget.server包 3.安装完成后修改web.config里面的 apikey ...

  5. Wince 6.0适用 .NET 使用HttpRequest的Post上传文件,服务端的Web API接收Post上传上来的文件 代码

    //调用的示例 private string fileName = "InStorageData.csv"; string filePath = parentPath + Comm ...

  6. go语言游戏服务端开发(三)——服务机制

    五邑隐侠,本名关健昌,12年游戏生涯. 本教程以Go语言为例.   P2P网络为服务进程间.服务进程与客户端间通信提供了便利,在这个基础上可以搭建服务. 在服务层,通信包可以通过定义协议号来确定该包怎 ...

  7. 【gRPC】C++异步服务端优化版,多服务接口样例

    官方的C++异步服务端API样例可读性并不好,理解起来非常的费劲,各种状态机也并不明了,整个运行过程也容易读不懂,因此此处参考网上的博客进行了重写,以求顺利读懂. C++异步服务端实例,详细注释版 g ...

  8. GPS服务端(上)-Socket服务端(golang)

    从第一次写GPS的服务端到现在,已经过去了八年时光.一直是用.net修修改改,从自己写的socket服务,到suppersocket,都是勉强在坚持着,没有真正的稳定过. 最近一段时间,服务端又出了两 ...

  9. 如何利用cURL和python对服务端和web端进行接口测试

    工具描述 cURL是利用URL语法在命令行方式下工作的文件传输工具,是开源爱好者编写维护的免费工具,支持包括Windows.Linux.Mac等数十个操作系统,最新版本为7.27.0,但是我推荐大家使 ...

随机推荐

  1. TreeView控件的CheckBox级联选中或取消

    背景: 在一个项目开发中遇到这样的要求:当选中树中一个节点时,需要同时选中其父节点,直至根节点.在取消一个节点的选中时,需要将其所有子节点取消选中,直至叶子节点.由于项目用户体验暂时可以不用考虑,直接 ...

  2. C++ 11 之学习总结

    感慨时间过的好快,C++ 11出来都5年了,现在才开始学习,但为时也不晚: 主要是网上及身边的朋友大肆宣扬C++ 11的某些优化,弄得别人心里痒痒的,所以就花了3天学习了点基本知识,相对于整个C++ ...

  3. JS增删改HTML表格

    要求如下: 写一个html页面,里面有一个表格,储存用户信息,包括:用户名,密码,姓名,邮箱,电话,qq,身份证号. 现在要通过js对表格进行动态的增删改查(只是内存操作即可): 首先,加载页面时用j ...

  4. Ubuntu14.04 安装 PHP cURL

    今天遇到 Fatal error: Call to undefined function curl_init() in /xxx/xxxx/www/application/library/Ku/Htt ...

  5. Lucene使用IKAnalyzer分词实例 及 IKAnalyzer扩展词库

    文章转载自:http://www.cnblogs.com/dennisit/archive/2013/04/07/3005847.html 方案一: 基于配置的词典扩充 项目结构图如下: IK分词器还 ...

  6. hover和mouseover,mouseout的区别

    说道hover和mouseover,mouseout的区别,不得不联系到mouseenter,mouseleave. mouseover,mouseout是指鼠标指针在穿过/离开被选元素或其子元素时触 ...

  7. ECMAScript整理笔记(持续更新....)

    参考文献: ECMAScript Array:http://www.jimmycuadra.com/posts/ecmascript-5-array-methods ECMAScript5兼容展示大全 ...

  8. OS X EI Capitan安装mcrypt

    OS X EI Capitan安装mcrypt   (我的博客原文:http://www.jmolboy.com/2015/12/01/mcrypt-extension-on-EI-Capitan/) ...

  9. [大牛翻译系列]Hadoop(11)MapReduce 性能调优:诊断一般性能瓶颈

    6.2.4 任务一般性能问题 这部分将介绍那些对map和reduce任务都有影响的性能问题. 技术37 作业竞争和调度器限制 即便map任务和reduce任务都进行了调优,但整个作业仍然会因为环境原因 ...

  10. jQuery1.9 $.browser 的替代方法

    jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support . 在更新的 2.0 版本中,将不再支持 IE 6/7/8. ...