1. 程式人生 > >cxf CXF搭建webService服務器

cxf CXF搭建webService服務器

pre port throw services tar style 客戶 3.1 factor

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服務器