cxf发布webservice简单例子:
cxf最小依赖的jar:
cxf-2.2.6.jar
jetty-6.1.21.jar
jetty-util-6.1.21.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.5.jar
附件中为以上jar
接口类:
import javax.jws.WebService;
@WebService
public interface IHelloWorld {
String sayHello();
}
实现类:
import javax.jws.WebService;
//@WebService(endpointInterface = "com.ddch.IHelloWorld", serviceName = "HelloWorld")
// 上面的可要可不要
public class HelloWorldImpl implements IHelloWorld {
public String sayHello() {
System.out.println("hello world call");
return "Hello World!";
}
}
服务器:
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public class SoapServer {
/**
* @param args
*/
public static void main(String[] args) {
IHelloWorld impl = new HelloWorldImpl();
JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();
factoryBean.setAddress("http://localhost:8089/helloworld");
factoryBean.setServiceClass(IHelloWorld.class);
//接口类
factoryBean.setServiceBean(impl);
factoryBean.create();
System.out.println("WS发布成功!");
// Endpoint.publish("http://localhost:8089/helloworld", new HelloWorldImpl());
}
}
运行后浏览器中输入http://localhost:8089/helloworld?wsdl返回xml页面说明成功
如果url中不加wsdl参数则报错:org.apache.cxf.interceptor.Fault: No such operation
客户端调用:
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
public class WebServiceClient {
public static void main(String[] args) throws Exception{
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:8089/helloworld?wsdl");
Object[] strs = client.invoke("sayHello");
System.out.println(strs[0]);
}
}
参考资料:http://wenku.baidu.com/view/2464a0272f60ddccda38a03f.html
分享到:
相关推荐
cxf webservice 简单例子 服务端 客户端 com.test.ClientTest 进行测试,导入myeclipse可以直接运行
现在主流的webService框架,一个是axis2,一个是cxf,本资源是基于cxf框架的简单例子
CXF webservice,mybatis持久层框架,增删改查实例;完整jar包;
学习CXF WebService入门实例一.pdf学习CXF WebService入门实例一.pdf
SSH整合cxf webservice实例
一个小例子希望能对你有所帮助 CXF webservice spring例子 将cxf2.4的lib复制到工程lib下
CXF WebService java实例 例子包括基本的 HelloWord列子 还有传递List ,Map的列子 另外还有webservice 文件下载上传的示例
使用 CXF 做 webservice 简单例子,用的是cxf-2.1.3.jar
mybatis+spring+cxf webservice服务 项目框架代码例子,绝对是可以参考的,信不信,只有下载之后才知道
cxf webservice 与spring整合的开发实例
CXF-webService实例(eclipse工程,有jar包,可运行) jax-ws和pojo两种方式发布
使用CXF开发简单HelloWorld实例
这是一个用cxf进行webservice开发的小例子,解决了no cxf bean等小问题,采用maven组织,接口可通过web发布,并带了测试demo。整个过程参考:http://developer.51cto.com/art/201205/333868.htm,大家可以继续完善
webservice天气预报例子cxf实例,
CXF实现WebService详解实例
cxf webservice实例
cxf webservice 实例(包括服务端及客户端代码),亲测可用,项目采用spring与cxf结合的,附件解压后看到两个项目,分部是服务端项目和客户端项目,启动tomcat服务器部署后,通过客户端右键运行java 的 mian方法代码...
cxf开发webservice简单实例:包括服务端与客户端并所有需要的jar,不要分啦。