webService之helloword(java)
webservice 远程数据交互技术
1.导入jar包(如果是 maven项目导入项目坐标)
2.创建服务
3.测试服务
我们使用maven来做测试服务
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>com.baidu.webservicetest01</groupId>
<artifactId>webservicetest01</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- jdk版本1.7 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- cxf ws开发包 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.1</version>
</dependency>
<!-- jetty 服务器包 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.0.1</version>
</dependency>
<!-- 使用log4j日志实现 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency> <!-- 使用rs客户端 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
</project>
服务接口
package com.baidu.test; import javax.jws.WebMethod;
import javax.jws.WebService; @WebService
public interface TestInterf {
@WebMethod
public void eat();
}
服务实现类
package com.baidu.test;
import javax.jws.WebService;
@WebService
public class TestImp implements TestInterf {
public void eat() {
System.out.println("该吃饭了");
} }
开启服务:
package com.baidu.test;
import javax.xml.ws.Endpoint;
public class PublishTest {
public static void main(String[] args) {
TestInterf tt=new TestImp();
String address="http://localhost:9991/TestInterf";
Endpoint.publish(address, tt);
System.out.println("服务启动了");
}
}
新建项目 和服务器的包结构必须相同

测试项目的 测试接口和服务器的接口必须一致
package com.baidu.test1;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService //标识可以连接服务
public interface TestInterf {
@WebMethod
public void eat();
}
测试服务
package com.baidu.test1;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
public class Test02 {
public static void main(String[] args) {
// 编写客户端 调用发布WebService服务
JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
jaxWsProxyFactoryBean.setServiceClass(TestInterf.class);
jaxWsProxyFactoryBean.setAddress("http://localhost:9991/TestInterf");
// 创建调用远程服务代理对象
TestInterf proxy = (TestInterf) jaxWsProxyFactoryBean.create();
proxy.eat();
}
}
pom.xml 客户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>com.baidu.webservicetest02</groupId>
<artifactId>webservicetest02</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies> <!-- 要进行jaxws 服务开发 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.1</version>
</dependency> <!-- 内置jetty web服务器 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.0.1</version>
</dependency> <!-- 日志实现 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
</dependencies> </project>
webService之helloword(java)的更多相关文章
- webService之helloword(java)rs
webservice之rs(helloworld) 1.pom.xml文件 <dependencies> <!-- 使用CXF RS开发 --> <dependency& ...
- struts1+spring+myeclipse +cxf 开发webservice以及普通java应用调用webservice的实例
Cxf + Spring+ myeclipse+ cxf 进行 Webservice服务端开发 使用Cxf开发webservice的服务端项目结构 Spring配置文件applicationCont ...
- C#动态webservice调用接口 (JAVA,C#)
C#动态webservice调用接口 using System; using System.Collections; using System.IO; using System.Net; using ...
- Axis2 webservice 之使用java调用webservice
在上一篇中写了一个简单了webservice,实现了一个sayHello功能.那么webservice写好之后我们如何使用Java程序来调用webservice呢? 一.java调用的webservi ...
- webservice之helloword(web)rs
spring整合webservice 1.pom.xml文件 <dependencies> <!-- cxf 进行rs开发 必须导入 --> <dependency> ...
- php调用webservice接口,java代码接收不到参数
前段时间做了一个项目的二次开发,有个功能是需要php调用java实现的webservice接口,并传递一些参数给接口,然后按照对方提供的接口说明文档进行传参调用,java那边有接收到请求,但是参数总是 ...
- WebService应用--使用java开发WebService程序
使用Eclipse开发第一个WebService程序,本示例采用的工具为Spring-Tool-Suite,和Eclipse没有本质的区别,开发环境jdk1.7 一.开发步骤: 1.新建名为WebSe ...
- webService之helloword(web)
spring 整合webservice pom.xml文件 <dependencies> <!-- CXF WS开发 --> <dependency> <gr ...
- 做Webservice时报错java.util.List是接口, 而 JAXB 无法处理接口。
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExc ...
随机推荐
- 【WH】MVC数据分页扩展类
public static class QueryableExtensions { #region 内存分页 /// <summary> /// 返回对象分页列表 /// </sum ...
- HTML标签归纳
首先,按下h1,再按下Tab键就可以变成<h1></h1>,Ctrl+d可以复制当前行,Ctrl+Alt+Insert可以快速新建文件,Home可以跳到当前行最前面,End同理 ...
- 基于Confluent.Kafka实现的Kafka客户端操作类使用详解
一.引言 有段时间没有写东西了,当然不是没得写,还有MongoDB的系列没有写完呢,那个系列还要继续.今天正好是周末,有点时间,来写新东西吧.最近公司用了Kafka做为消息的中间件,最开始写的那个版本 ...
- IIS站点工作原理与ASP.NET工作原理
IIS站点工作原理与ASP.NET工作原理 一.IIS IIS 7.0工作原理图 两种模式: 1.用户模式(User Mode)(运行用户的程序代码.限制在特定的范围内活动.有些操作必须要受到Ker ...
- UML 图C#
继承关系(类1继承类2) 代码: class Class1:Class2 { } class Class2 { } 实现(实现接口) 代码: interface interface1 { void s ...
- 11. 标准库浏览 – Part II
第二部分包含了支持专业编程工作所需的更高级的模块,这些模块很少出现在小脚本中. 11.1. 输出格式 reprlib 模块为大型的或深度嵌套的容器缩写显示提供了 :repr() 函数的一个定制版本: ...
- 优化myeclipse启动速度以及解决内存不足问题
解决myeclipse内存不足问题: 使用 MyEclipse 开发项目后,随着项目文件的增多,以及运行时间的增加,实际上 MyEclipse 所消耗的内存是会一直增大的,有的时候会出现 MyEcli ...
- 事件类型(js)
焦点事件:在页面获得或失去焦点时触发. 与document.hasFocus和document.activeElement属性配合,可以得到用户在页面的行踪. blur:元素失去焦点时触发.这个事件不 ...
- Luogu 3424 [POI2005]SUM-Fibonacci Sums
Solution 没有任何算法, 只要会$for$ 就能AC... 我们观察到, 如果有一个位置 的$F_i$ 的系数$b_i$ 为2, 那么只需要把 $b_{i-2}+1,b_{i+1}+1$即可. ...
- PHP学习笔记(二)
1.表单 PHP 的 $_GET和 $_POST用于检索表单中的值,比如用户输入. $_GET和$_POST变量分别用于收集来自 method="get" 和method=&quo ...