CXF发布webservice

CXF 是两个框架集合,基于XFire.

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

如果javaPorject工程需要引入以下jar

cxf-core-3.0.0-milestone2.jar

geronimo-servlet_3.0_spec-1.0.jar

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.jar

jetty-server-8.1.14.v20131031.jar

jetty-util-8.1.14.v20131031.jar

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" />  

 

你可能感兴趣的:(webservice,CXF)