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 ...
随机推荐
- python 数据类型 总结
按存储空间的占用分(从低到高) 数字 字符串 集合:无序,即无序存索引相关信息 元组:有序,需要存索引相关信息,不可变 列表:有序,需要存索引相关信息,可变,需要处理数据的增删改 字典:无序,需要存k ...
- java的几个日志框架log4j、logback、common-logging
开发工作中每个系统都需要记录日志,常见的日志工具有log4j(用的最多),slf4j,commons-loging,以及最近比较流行的logback 以前只是在项目中用log4j,更多的是参考下配置文 ...
- Android——Activity练习
manifests里的AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> < ...
- Eclipse中的maven项目搭建
一.eclipse中的maven设置 1.打开“首选项”----> "maven"---->"Installations".用来查看maven的使用 ...
- BZOJ 4521 [CQOI2016]手机号码 - 数位DP
Description 在$[L, R]$找出有几个数满足两个条件 : 1 : 不同时含有$4$ 和 $8$ 2 : 至少有$3$个相邻的数相同 Solution 非常容易的数位DP, $pos$ 为 ...
- UI设计教程分享:关于海报的合成过程
一张好的产品创意合成海报,能瞬间提升商品价值感,同时场景和相关元素的融入,让消费者瞬间明白商品属性及内涵.同时为商品营造的使用场景拥有更强的代入感,从而刺激转化.好的创意合成海报能为消费者带来视觉冲击 ...
- How to convert a PDF file to JPEGs using PHP
Hey, Today I would like to show you how we can convert PDF to JPEG using imagick extension. Imagick ...
- Spring ApplicationContext(一)初始化过程
Spring 容器 ApplicationContext(一)初始化过程 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) ...
- Ubunton安装mysql
#手下下载tar.gz包#首先手工建立mysql用户和用户组 > groupadd mysql > useradd -r -g mysql mysql#然后就是安装的解压 编译安装 > ...
- Sophus链接错误
错误指示如下: CMakeFiles/run_vo.dir/run_vo.cpp.o: In function `main': run_vo.cpp:(.text.startup+0x1086): u ...