今天和大家分享 使用 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. Cocos2d-x 3.0标签类Label

    Cocos2d-x 3.0后推出了新的标签类Label,这种标签通过使用FreeType[1]来使它在不同的平台上有相同的视觉效果.由于使用更快的缓存代理,它的渲染也将更加快速.Label提供了描边和 ...

  2. UI4_UITableViewEdit

    // // AppDelegate.m // UI4_UITableViewEdit // // Created by zhangxueming on 15/7/13. // Copyright (c ...

  3. 继承关系在内存和DB中的映射

    使用 将若干相似的类映射为单表,对拥有许多特殊数据的类使用具体表继承. 对高层次使用类表继承,对低层次使用具体表继承. Single Table Inheritance 在DB中将类继承层次设计为一个 ...

  4. 4月12日学习笔记——jQuery事件

    下面是在 jQuery 中最常使用的 bind()方法举例:$("#testDiv4").bind("click", showMsg); 我们为 id 是 te ...

  5. Ant打jar包指定MainClass

    一般用ant打jar的时候不用指定程序的入口!这个jar一般是给其他app引用的. 但是如果该jar就是程序的启动jar.例如: java -jar abc.jar  这个时候需要指定jar的入口类! ...

  6. AutoEventWireup="false"

    在 Web 服务器控件中,某些事件(通常是 Click 事件)会导致窗体被回发到服务器.HTML 服务器控件和 Web 服务器控件(如 TextBox 控件)中的更改事件将被捕获,但不会立即导致发送. ...

  7. UML类图新手入门级介绍

    UML类图新手入门级介绍 举一个简单的例子,来看这样一副图,其中就包括了UML类图中的基本图示法. 首先,看动物矩形框,它代表一个类(Class).类图分三层,第一层显示类的名称,如果是抽象类,则就用 ...

  8. 工厂方法(Factory Method)模式

    一.工厂方法(Factory Method)模式 工厂方法(FactoryMethod)模式是类的创建模式,其用意是定义一个创建产品对象的工厂接口,将实际创建工作推迟的子类中. 工厂方法模式是简单工厂 ...

  9. 【风马一族_Python】 安装pip与Numpy

    ------------------------------------------------------------------------------------------------- 原因 ...

  10. javascript Date 函数的坑

    Javascrip中对日期的解析.格式化简直是混乱不堪,各种的坑,攻城狮们多小心.   1. 不要用 Date("yyyy-mm-dd") 构造函数解析字符串. IE.firefo ...