0.新建一个项目取名wsserver. pom.xml 文件如下

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sidonia</groupId>
<artifactId>wsserver</artifactId>
<version>0.0.1-SNAPSHOT</version> <properties>
<cxf.version>3.1.4</cxf.version>
</properties> <dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>

1.新建一个interface 取名 HelloWorld

package com.test.hello;

import javax.jws.WebService;

@WebService
public interface HelloWorld {
public void sayHello();
}

2.新建一个实现类,取名HelloWorldImpl

package com.test.hello;

import javax.jws.WebService;

@WebService(endpointInterface="com.test.hello.HelloWorld",serviceName="HelloWorldWS")
public class HelloWorldImpl implements HelloWorld{ public void sayHello() {
System.out.println("hello world");
}
}

3.新建一个包含main方法的ServerMain类

public class ServerMain {
public static void main(String[] args) throws Exception {
HelloWorld helloWorldImpl = new HelloWorldImpl();
Endpoint.publish("http://localhost:1234/ws", helloWorldImpl);
System.out.println("webservice 暴露成功");
}
}

4.这时候访问上面这个地址,就可以看见下面这个xml

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://hello.test.com/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
name="HelloWorldWS" targetNamespace="http://hello.test.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://hello.test.com/" elementFormDefault="unqualified"
targetNamespace="http://hello.test.com/" version="1.0">
<xs:element name="sayHello" type="tns:sayHello" />
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse" />
<xs:complexType name="sayHello">
<xs:sequence />
</xs:complexType>
<xs:complexType name="sayHelloResponse">
<xs:sequence />
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloWorld">
<wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello"></wsdl:input>
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldWSSoapBinding" type="tns:HelloWorld">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document" />
<wsdl:input name="sayHello">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldWS">
<wsdl:port binding="tns:HelloWorldWSSoapBinding" name="HelloWorldImplPort">
<soap:address location="http://localhost:1234/ws" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

5.现在写客户端 取名wsclient

6.cmd 到D盘找个合适的地方 命令行执行 wsdl2java http://localhost:1234/ws?wsdl,这时候这里就会根据这个wsdl生成相应的类,把它考到客户端项目下面

7.新建一个ClientMain类

package com.test.hello;

public class ClientMain {
public static void main(String[] args) {
HelloWorldWS factory = new HelloWorldWS(); //显然HelloWorldWS是一个工厂类
HelloWorld helloWorld = factory.getHelloWorldImplPort();
helloWorld.sayHello();
}
}

一运行,服务器端控制台就会打印出hello world

CXF学习(2) helloworld的更多相关文章

  1. AspectJ基础学习之三HelloWorld(转载)

    AspectJ基础学习之三HelloWorld(转载) 一.创建项目 我们将project命名为:aspectjDemo.然后我们新建2个package:com.aspectj.demo.aspect ...

  2. [Cocos2d-x for WP8学习笔记] HelloWorld结构分析

    先来看一下目录结构: Assets:游戏资源文件,图片音频等,Resource文件夹也有类似功能 include:用于放置游戏头文件 Shaders:渲染器着色器文件(大雾) cocos2dorig. ...

  3. [Cocos2d-x for WP8学习笔记] HelloWorld

    Cocos2d-x 是一个支持多平台的 2D 手机游戏引擎,使用 C++ 开发,基于OpenGL ES,基于Cocos2d-iphone,支持 WOPhone, iOS 4.1, Android 2. ...

  4. Emit学习(1) - HelloWorld

    之前看过Dapper(使用到了Emit), CYQ.Data(另一种思路,没有使用Emit)类的框架之后, 也想自己做一个小框架玩一下, 不过此时能力太过欠缺, 做不了Cyq.Data或者PDF.Ne ...

  5. CXF学习(4) 处理无法自动转换的复合数据类型

    只贴出服务端代码 1.Service接口类 package com.test.hello; import java.util.Map; import javax.jws.WebService; imp ...

  6. 从零开始学习C#——HelloWorld(一)

    从零开始学习C# 老规矩Hello World 您的第一个程序 visual studio 如何使用就不说了 //编程的开始,Hello World! program in C# using Syst ...

  7. MSIL学习------从HelloWorld开始

    我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=3889z1y72b28 ...

  8. Struts2学习:HelloWorld

    项目结构: 1.用IDEA新建一个SpringBoot+Maven的项目 2.新建的项目是没有webapp.WEB-INF.与web.xml文件的,需要在下图中添加: 3.在pom.xml引入stru ...

  9. (转)Android学习笔记②——HelloWorld的创建已经基本知识

    开发第一应用 可以开发属于自己的应用,是否有点小激动?好吧!让我们开始,首先点击Start a new Android Studio Project创建工程:接下来需要输入应用名称(第一个字母要大写) ...

随机推荐

  1. java抓取快递信息

    package zeze; import java.io.IOException; import org.jsoup.Connection; import org.jsoup.Jsoup; impor ...

  2. 使用uwsgi 部署python web服务

    uwsgi, wsgi协议的一个很好的实现,源码在这里:https://github.com/unbit/uwsgi c语言编写,有兴趣可以研究下. 上DEMO: wsgi_server.py def ...

  3. Extjs TabPanel 选项卡延迟加载

    Extjs TabPanel 选项卡延迟加载 说明: Ext中用到tabpanel选项卡控件, 选项卡页签默认是延迟加载的, 当用户手工切换到某页签下时该页签才会加载, 在页签没有加载前, 用户对该页 ...

  4. WPF 中更新界面信息

    1.Dispatcher.BeginInvoke int ii = 0; new Thread(new ParameterizedThreadStart((i) => { while (true ...

  5. Split Array Largest Sum

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  6. METEOR 及ANGULARJS

    最近学习:METEOR 及ANGULARJS,收藏相关资源: 1.METEOR 中文书:http://zh.discovermeteor.com/ 2.METEOR 及ANGULARJS 联合开发:h ...

  7. 【leetcode】Unique Binary Search Trees II

    Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) ...

  8. Html5 postMessage

    解释: 跨文档消息传输Cross Document Messaging. 编写代码前注意判断浏览器是否支持Html5 实例: b页面向a页面发送消息. <!DOCTYPE> <htm ...

  9. shell 脚本编程概述

    环境变量 ? 退出状态码 (成功) (未知错误) (误用 shell 命令) (命令不可执行) (没找到命令) (无效退出状态) +x( linux 信号 X 的严重错误) ( ctrl c 终止程序 ...

  10. 【python】类中的super().__init__()

    来源:百度知道 python中的super( test, self).__init__()是什么意思? 首先找到test的父类(比如是类A),然后把类test的对象self转换为类A的对象,然后&qu ...