今天和大家分享 使用 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. HTML+CSS学习总结:

    1. 注释:<div> 是一个块级元素,也就是说,浏览器通常会在 div 元素前后放置一个换行符. 提示:请使用 <div> 元素来组合块级元素,这样就可以使用样式对它们进行格 ...

  2. UI3_UICollectionViewMuti

    // AppDelegate.m // UI3_UICollectionViewMuti // // Created by zhangxueming on 15/7/16. // Copyright ...

  3. WIN10主动推升级,有点意思

    不论正与盗,皆推升级,是否一样可用?

  4. js 如何获取文本框中光标索引位置

    function getTxt1CursorPosition(){ var oTxt1 = document.getElementById("txt1"); var cursurP ...

  5. JPG各种输入框样式

    输入框景背景透明:<input style="background:transparent;border:1px solid #ffffff"> 鼠标划过输入框,输入框 ...

  6. android 在标题栏加上按钮

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowF ...

  7. 通知栏发送消息Notification(可以使用自定义的布局)

    一个简单的应用场景:假如用户打开Activity以后,按Home键,此时Activity 进入-> onPause() -> onStop() 不可见.代码在此时机发送一个Notifica ...

  8. IIS6下, web.config配置为targetFramework="4.0"时出404错误

    打开IIS管理器,在"Web 服务扩展" 中 将ASP.NET v4.0设置为允许就好了.这个选项默认是禁止的.

  9. C#中窗体的互相访问

    1.在父窗体中构造子窗体对象时,将父窗体传递过去: 如:FrmSub frm=new FrmSub(this);//this代表父窗体 2.将父窗体中要访问的变量和方法修改为public 3.在子窗体 ...

  10. Spark 大数据平台 Introduction part 2 coding

    Basic Functions sc.parallelize(List(1,2,3,4,5,6)).map(_ * 2).filter(_ > 5).collect() *** res: Arr ...