首页 > 代码库 > cxf CXF搭建webService服务器

cxf CXF搭建webService服务器

http://observer.blog.51cto.com/4267416/1231205

手动发布:

public class ServerMain {

public static void main(String[] args) {
GradeService service = new GradeServiceImpl();
Endpoint.publish("http://localhost/webservices/services/Service", service);
}
}

客户端调用

package com.test.service;public class ClientMain {public static void main(String[] args) throws Exception {GradeService_Service service = new GradeService_Service();GradeService gradeServiceImplPort = service.getGradeServicePort();System.out.println(gradeServiceImplPort.getGradeName(111));//JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();//Client client = clientFactory.createClient("http://localhost/webservices/services/Service?wsdl");//Object[] result = client.invoke("getGradeName", 11);//System.out.println(result[0]);}}

使用wsdl2java 生成的代码,运行时出现错误,删除包xfire-all-1.2.6可以运行了,实际不用导入任何包就可以运行。

注:wsdl2java 在 apache-cxf-3.1.12 的bin目录下面

cxf CXF搭建webService服务器