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)的更多相关文章

  1. webService之helloword(java)rs

    webservice之rs(helloworld) 1.pom.xml文件 <dependencies> <!-- 使用CXF RS开发 --> <dependency& ...

  2. struts1+spring+myeclipse +cxf 开发webservice以及普通java应用调用webservice的实例

    Cxf + Spring+ myeclipse+ cxf 进行  Webservice服务端开发 使用Cxf开发webservice的服务端项目结构 Spring配置文件applicationCont ...

  3. C#动态webservice调用接口 (JAVA,C#)

    C#动态webservice调用接口 using System; using System.Collections; using System.IO; using System.Net; using ...

  4. Axis2 webservice 之使用java调用webservice

    在上一篇中写了一个简单了webservice,实现了一个sayHello功能.那么webservice写好之后我们如何使用Java程序来调用webservice呢? 一.java调用的webservi ...

  5. webservice之helloword(web)rs

    spring整合webservice 1.pom.xml文件 <dependencies> <!-- cxf 进行rs开发 必须导入 --> <dependency> ...

  6. php调用webservice接口,java代码接收不到参数

    前段时间做了一个项目的二次开发,有个功能是需要php调用java实现的webservice接口,并传递一些参数给接口,然后按照对方提供的接口说明文档进行传参调用,java那边有接收到请求,但是参数总是 ...

  7. WebService应用--使用java开发WebService程序

    使用Eclipse开发第一个WebService程序,本示例采用的工具为Spring-Tool-Suite,和Eclipse没有本质的区别,开发环境jdk1.7 一.开发步骤: 1.新建名为WebSe ...

  8. webService之helloword(web)

    spring 整合webservice pom.xml文件 <dependencies> <!-- CXF WS开发 --> <dependency> <gr ...

  9. 做Webservice时报错java.util.List是接口, 而 JAXB 无法处理接口。

    Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExc ...

随机推荐

  1. c#Md5 32位加密结果少了两个0的原因

    今天碰到一个问题, md5加密之后与网站上md5加密少了两位, 仔细看区别是少了两个零 E1ADC3949BA59ABBE56E057F2F883E    我的md5 E10ADC3949BA59AB ...

  2. 动态加载JS脚本到HTML

    如果用原生态的js 有2中方法  1.直接document.write  <script language="javascript">      document.wr ...

  3. Android开发颜色大全

    <!-- dialog背景颜色 --> <color name=</color> <color name="white">#FFFFFF& ...

  4. (转)在WCF服务的ServiceReferences.ClientConfig中使用相对路径

    问题: Silverlight项目中添加服务引用后会在Silverlight项目中生成一个ServiceReferences.ClientConfig文件,这个文件中包含了引用服务的绑定(bindin ...

  5. JAVA 8.20 游戏:四子连(Java&C++)

    (游戏:四子连 )四子连是一个两个人玩的棋盘游戏,在游戏中,玩家轮流将有颜色的棋子放在一个六行七列的垂直悬挂的网格中:         这个游戏的目的是在对手实现一行.一列或者一条对角线上有四个相同颜 ...

  6. iOS.Thread.OSAtomic

    1. 原子操作 (Atomic Operations) 编写多线程代码最重要的一点是:对共享数据的访问要加锁. Shared data is any data which more than one ...

  7. linux下gcc默认搜索的头文件及库文件路径

    转自:https://blog.csdn.net/fd315063004/article/details/7925854 一.头文件 gcc 在编译时如何去寻找所需要的头文件:※所以header fi ...

  8. UVA 11324.The Largest Clique tarjan缩点+拓扑dp

    题目链接:https://vjudge.net/problem/UVA-11324 题意:求一个有向图中结点数最大的结点集,使得该结点集中任意两个结点u和v满足:要目u可以到达v,要么v可以到达u(相 ...

  9. 【搜索】Fliptile

    #include<stdio.h> #include<stdlib.h> #include<string.h> ; ; typedef long long ll; ...

  10. eclipse安装提要

    svn 插件安装http://subclipse.tigris.org/update_1.12.x教程地址http://jingyan.baidu.com/article/f71d60376b4c57 ...