需要导入cxf需要的jar文件
首先需要有一个接口:
import java.util.List;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface HelloWord {
String sayHi(@WebParam(name="text")String text);
}
实现类:
import java.util.HashMap;
import javax.jws.WebService;
@WebService(endpointInterface="com.sg.service.HelloWord",serviceName="HelloWord")
public class HelloWordImpl implements HelloWord{
Map<Integer,User> userMap = new HashMap<Integer, User>();
@Override
public String sayHi(String text) {
return "hello-->"+text;
}
}
服务端发布程序:
package com.sg.service;
import javax.xml.ws.Endpoint;
import org.apache.cxf.configuration.spring.JAXBBeanFactory;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.endpoint.Server;
public class HolleWordAPP {
public static void main(String[] args) {
System.out.println("web service start..............");
HelloWordImpl helloWordImpl = new HelloWordImpl();
String address = "http://localhost:8080/helloword";
Endpoint.publish(address, helloWordImpl);
System.out.println("web service end................");
//第二种发布服务方式
/*
JaxWsServerFactoryBean jsfb = new JaxWsServerFactoryBean();
//设置服务在服务器上部署的位置
jsfb.setAddress("http://localhost:8080/helloword");
//设置服务暴露的接口实现类
jsfb.setServiceClass(helloWordImpl.getClass());
Service service = (Service)jsfb.create();
service.start();
*/
}
}
发布之后可以直接访问http://localhost:8080/helloword?wsdl
会把相应的xml文件显示出来
下面是客户端程序:
package com.sg.client;
import java.util.ArrayList;
import java.util.List;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.sg.service.HelloWord;
import com.sg.service.User;
public class HelloWorldClient {
public static void main(String[] args) {
List<User> users = new ArrayList<User>();
JaxWsProxyFactoryBean jpfb = new JaxWsProxyFactoryBean();
jpfb.getInInterceptors().add(new LoggingInInterceptor());
jpfb.getOutInterceptors().add(new LoggingOutInterceptor());
jpfb.setServiceClass(HelloWord.class);
jpfb.setAddress("http://localhost:8080/helloword");
HelloWord hw = (HelloWord)jpfb.create();
User u = new User();
u.setName("zhangsan");
u.setDescription("test");
users.add(u);
System.out.println(hw.sayHi("sungang"));
System.out.println(hw.sayHiToUser(u));
}
}
相关推荐
cxf开发webservice简单实例:包括服务端与客户端并所有需要的jar,不要分啦。
实现客户端(一个javaweb项目)对服务端(javaweb项目)方法的调用, 实际上就是发送和接收消息,实现两个系统间消息的传递 jar包都在lib项目里 具体再解释一下,服务端需要 接口类,实现类,cxf 服务端xml,和一个...
cxf客户端调用axis服务端流程
cxf webservice 简单例子 服务端 客户端 com.test.ClientTest 进行测试,导入myeclipse可以直接运行
cxf生成客户端 服务端代码
CXF建立webservice服务端和客户端,发送格式为XML,服务端进行XML解析,并将收到请求报文解析入库,数据库为mysql。
整理了一上午,测试通过,cxf服务端和客户端所需jar包
cXF实现webservice 服务端和客户端
使用cxf和spring开发基于https的webservice服务端以及客户端样例
cxf 与 Spring 结合,此例子中包含服务端和客户端, 2个工程都是与SSH 结合使用。相信对刚接触的朋友有用!
cxf客户端调用axis服务端流程.docxcxf客户端调用axis服务端流程.docx
源码里面包含了了一个简单的插入功能,主要是为了测试mybatis是否连接上数据库的时候写的测试类,作为一个刚学java,被抓壮丁的写服务器端的妹子,我只想说,画了我3周才解决了所有的错误啊,真的要自己因为不懂乱写...
使用cxf wsdl2java生成webservice客户端命令
cxf 完整的服务端客户端
CXF与web项目服务端整合的例子以及客户端调用详细说明
NULL 博文链接:https://javastudyeye.iteye.com/blog/1297557
CXF 一个完整的webService(整合客户端和服务端),自己开发,自己测试,完全有效,整合集成了客户端和服务端双向的工能。
使用cxf和spring开发基于https的webservice服务端以及客户端样例源码.rar
完整整合spring4、cxf3和maven3的服务端和客户端项目。
cxf webservice 实例(包括服务端及客户端代码),亲测可用,项目采用spring与cxf结合的,附件解压后看到两个项目,分部是服务端项目和客户端项目,启动tomcat服务器部署后,通过客户端右键运行java 的 mian方法代码...