你好,游客 登录 注册 搜索
背景:
阅读新闻

Spring3.0+CXF WebService开发

[日期:2012-12-20] 来源:Linux社区  作者:sundenskyqq [字体:大 中 小]

第一步,测试wsdl:

访问 http://ip:8080/项目路径/services/spring cxf配置文件中的address?wsdl,例如:http://129.0.0.0:8080/abc/services/WorkUnitInfo?wsdl

第二步:测试webservice

1、WebService 客户端 spring 配置文件 wsclient-context.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
 xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">

 <bean id="workUnitInfoClient" class="com.cslc.crius.common.ws.cxf.server.IWorkUnitInfo"
  factory-bean="workUnitInfoFactory" factory-method="create">
 </bean>
 
 <bean id="workUnitInfoFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
  <property name="serviceClass" value="com.cslc.crius.common.ws.cxf.server.IWorkUnitInfo"/>
  <property name="address" value="http://localhost:8080/viminal/services/WorkUnitInfo?wsdl"></property>
 </bean>
 
</beans>
<!-- END SNIPPET: beans -->

2、调用WebService接口的测试程序

package com.cxf.client;


import java.util.Date;
import java.util.List;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.cslc.crius.common.utils.DateUtils;
import com.cslc.crius.common.ws.cxf.server.IWorkUnitInfo;
import com.cslc.crius.viminal.vo.WorkUnitVO;

public final class Client {

    private Client() {
    }

    public static void main(String args[]) throws Exception {
        // START SNIPPET: client
        ClassPathXmlApplicationContext context
            = new ClassPathXmlApplicationContext(new String[] {"client/wsclient-context.xml"});

        IWorkUnitInfo work = (IWorkUnitInfo)context.getBean("workUnitInfoClient");
        Date date = DateUtils.parseDate("2012-10-01");
        List<WorkUnitVO> r = work.getWorkUnitByDate(date);
        for (int i=0;i<r.size();i++) {
         System.out.println(r.get(i).getWorkUnitTitle());
        }
        System.exit(0);
        // END SNIPPET: client
    }
}

基本步骤就是上面这些,对外提供的接口就是上面测试wsdl所用的url。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款