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. thymeleaf 格式化时间

    运用Thymeleaf模板后,前台的时间显示发生变化,和数据库不一致 HTML页面中格式如下: <td th:text="${fleeceRecord.cashmereDate}&qu ...

  2. mysql 安装后出现 10061错误

    #服务器端  提示 The vervice already exists! The current server installed #mysqld 服务没有启动 解决办法 移除原来的mysql服务  ...

  3. hdu 5532 (LIS) Almost Sorted Array

    http://acm.hdu.edu.cn/showproblem.php?pid=5532 题意大致是一组数中去掉一个数后问剩下的数是否构成非严格单调序列 正反各跑一遍最长非严格连续子序列,存在长度 ...

  4. HDOJ2089 不要62

    原题链接 数位\(DP\)入门题. 记录前一个枚举到的数位,在每次枚举的时候避开\(4\),如果前一个数位为\(6\),还要跳过\(2\). 然后套上记搜模板就好. #include<cstdi ...

  5. Java界面编程—布局管理

    布局是指容器中组件的排列方式 常用的布局管理器 布局管理器名称 所属类包 说明 FlowLayout(流式布局) java.awt 组件按照加入的先后顺序.按照设置的对齐方式从左向右排列,一行排满后到 ...

  6. MySQL中的联结表

    使用联结能够实现用一条SELECT语句检索出存储在多个表中的数据.联结是一种机制,用来在一条SELECT语句中关联表,不是物理实体,其在实际的数据库表中并不存在,DBMS会根据需要建立联结,且会在查询 ...

  7. Python之路(第十三篇)time模块、random模块、string模块、验证码练习

    一.time模块 三种时间表示 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp) : 通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.(从 ...

  8. Subarray Sum Equals K LT560

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  9. Asp.Net 启用全局IE兼容模式

    Asp.Net 启用全局IE兼容模式,不失为一个种简单最有效的解决方案: <system.webServer> <!-- 配置全局兼容 --> <httpProtocol ...

  10. 【记录】解决VS2015调试Xamarin程序一闪而过(使用微软ANDROID模拟器)

    越来越多的人去安装Visual Studio 2015,也会去试试其中的C#跨平台开发利器Xamarin,但是也会发现很多问题. 我相信我不会是唯一遇到以下问题的,也不会是最后一个,特此记录. 微软的 ...