CXF發佈webservice


CXF 是兩個框架集合,基於XFire.html

下載地址http://cxf.apache.org/download.html 我使用的是3.0versionjava

若是javaPorject工程須要引入如下jarweb

cxf-core-3.0.0-milestone2.jarspring

geronimo-servlet_3.0_spec-1.0.jarapache

jetty-continuation-8.1.14.v20131031.jar服務器

jetty-http-8.1.14.v20131031.jar框架

jetty-io-8.1.14.v20131031.jarjetty-security-8.1.14.v20131031.jaride

jetty-server-8.1.14.v20131031.jar測試

jetty-util-8.1.14.v20131031.jarspa

asm-3.3.1.jar

wsdl4j-1.6.3.jar

neethi-3.0.3.jar

commons-logging-1.1.1.jar

xmlschema-core-2.1.0.jar

 

 

如下代碼部分:

 接口

package org.lgg.webservice;

import javax.jws.WebService;
/**
 * CXFwebserviveD定義
 * @author  wangsl
 *
 */
@WebService
public interface CmsService {
 /**
  * 獲取當前登陸用戶
  * @param name
  * @return
  */
 public String getCurrUser(String name);

}

 

 

實現類

package org.lgg.webservice;

import javax.jws.WebService;
/**
 * webservice 接口實現
 * @author  wangsl
 *
 */
@WebService(endpointInterface="org.lgg.webservice.CmsServiceWs",serviceName="CmsServiceWs")
public class CmsServiceWs implements CmsService {
    
 @Override
 public String getCurrUser(String name) {
     String result="你好,"+name+" 歡迎登陸! ";
  return result;
 }
 
}

測試類

package org.lgg.test;

import javax.xml.ws.Endpoint;
import org.lgg.webservice.CmsService;
import org.lgg.webservice.CmsServiceWs;

public class TestServceMain {
 
 public static void main(String[] args) {
  CmsService ms=new CmsServiceWs();
  Endpoint.publish("http://10.111.126.238:9999/LGCMS", ms);
  System.out.println("cxfWeb已經暴露成功=======");
 }

}

 

http://10.111.126.238:9999/LGCMS?wsdl ok這一步能打開已經發布成功 服務器就發佈成功

 

下面是客戶端調用 

若是 javaproject 客戶端調用 s

wsdl2java 命令講遠程wsdl解析存入本地

如wsdl2java http://10.111.126.238:9999/LGCMS?wsdl   將解析到本地client 工程src下生成一段解析好的文件

創建測試文件

package org.lgg.test;

import org.lgg.webservice.CmsServiceWs;
import org.lgg.webservice.CmsServiceWs_Service;

public class TestClient {
  
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  CmsServiceWs_Service factroy=new CmsServiceWs_Service() ;
  CmsServiceWs ms=factroy.getCmsServiceWsPort();
  System.out.println(ms.getCurrUser("張三"));
 }

}

 

輸出你好,張三 歡迎登陸!  說明調用成功

 

 

CXF+Spring整合須要引入xmlns:jaxws="http://cxf.apache.org/jaxws"

xsil:schemaLation="http://cxf.apache.org/jaxws

                            http://cxf.apache.org/schemas/jaxws.xsd"

 

"

spring 配置加入

 <import resource="classpath:META-INF/cxf/cxf.xml" />  

 <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  

  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  

相關文章
相關標籤/搜索