xfire+webservice(服务器配置篇)

    今天终于把webservice搞完了,写个总结,我是在原来的项目中,进行webservice扩展的。

    首先在已完成的项目中加入webservice支持,如图

   

 

下一步

   

    接下来选择xfire包

   

    finish 完成。

    这样在你的项目中会产生xfire的工具包,这里完全可以自己将所需要的包放入lib下。

    由于我的原始项目是ssh的,这里就不再说了,接下来进行xfire配置。

    首先web.xml

  <!-- begin XFire 配置 -->
    <servlet>   
       <servlet-name>xfire</servlet-name>   
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>   
    <servlet-mapping> 
       <servlet-name>xfire</servlet-name>
       <url-pattern>*.ws</url-pattern>
    </servlet-mapping>
    
 <!-- 配合Spring容器中XFire一起工作的Servlet-->  
   <servlet>
    <servlet-name>XFireServlet</servlet-name>
    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>XFireServlet</servlet-name>
    <url-pattern>/servlet/XFireServlet/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>XFireServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

 接下来在src下面建立xfire-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <!-- 引入XFire预配置信息 -->
    <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
    <!-- 定义访问的url -->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
       <property name="urlMap">             
           <map>                 
              <entry key="/webservices.ws">                  
                  <ref bean="webservices" />                 
              </entry>             
           </map>         
       </property>     
    </bean>     

    <!-- 使用XFire导出器 -->
    <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true">
       <!-- 引用xfire.xml中定义的工厂 -->
       <property name="serviceFactory" ref="xfire.serviceFactory" />
       <!-- 引用xfire.xml中的xfire实例 -->
       <property name="xfire" ref="xfire" />
    </bean>
    
    <bean id="webservices" parent="baseWebService">
       <!-- 业务服务bean -->
       <property name="serviceBean" ref="webservicesService" />
       <!-- 业务服务bean的窄接口类 -->
       <property name="serviceClass" value="com.seavision.huayi2.service.IWebservice" />
    </bean>
</beans>

      这里说说为什么定义窄接口,原因xfire会导出spring整个接口,不能控制那些暴露给用户,这样做就不会将所有接口暴露给用户。

    下来说说,在项目下生成的services.xml,这个里面是按照spring2.0的命名空间配置的,所以改写这个xml

    

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

 这样就不会出错了。

 这样启动Tomcat,如果启动时抛以下异常,则删掉发布后lib中的spring1.2版本,原因与spring2冲突

 org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null"还有一些就不多说了。

 服务器启动后,在项目名后面键入/services 则出现wsdl,另存为即可。

 

 看看我的spring配置文件 ,和上面的xfire-servlet.xml对应起来。

<!-- webservice -->
	<bean id="iwebserviceTarget" class="com.seavision.huayi2.service.impl.WebserviceImpl">
         <property name="businsesslogDAO">
			<ref local="TBusinsessLogDAO"/>
		</property>
		<property name="sationmonthreportDAO">
			<ref local="TStationMonthReportDAO"/>
		</property>		
	</bean>
     <bean id="webservicesService" parent="txProxyTemplate">
		<property name="target" ref="iwebserviceTarget">
		</property>
	</bean>

 

    service即实现类如下,此代码仅为本人项目代码,仅供参考,切勿抄送

   

public interface IWebservice {
	/***************
	 * 取得基础数据表中所有数据,以基础数据建立日期的倒叙排序(HY0703)
	 * @throws DAOException 
	 * ******************/
	public List<TBusinsessLog> getYeWuList();
	/*******************************
	*增加工作站月工作计划信息
	********************************/
	public boolean insertYueJiHua(TStationMonthReport tStationMonthReport);
}

 实现类

public class WebserviceImpl implements IWebservice{
	TBusinsessLogDAO  businsesslogDAO;
	TStationMonthReportDAO    sationmonthreportDAO;

	
	public TStationMonthReportDAO getSationmonthreportDAO() {
		return sationmonthreportDAO;
	}


	public void setSationmonthreportDAO(TStationMonthReportDAO sationmonthreportDAO) {
		this.sationmonthreportDAO = sationmonthreportDAO;
	}


	public TBusinsessLogDAO getBusinsesslogDAO() {
		return businsesslogDAO;
	}


	public void setBusinsesslogDAO(TBusinsessLogDAO businsesslogDAO) {
		this.businsesslogDAO = businsesslogDAO;
	}


	public List<TBusinsessLog> getYeWuList(){
		System.out.println("调用ok");
		String hql="from TBusinsessLog as t order by t.cretateDate desc";
		List<TBusinsessLog> list= new ArrayList<TBusinsessLog>();
		try {
			List blist=businsesslogDAO.find(hql);
			for(int i=0;i<blist.size();i++){
				list.add((TBusinsessLog) blist.get(i));
			}
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	/*******************************
	*增加工作站月工作计划信息
	********************************/
	public boolean insertYueJiHua(TStationMonthReport tStationMonthReport) {	
		System.out.println("调用ok");
		try {
			System.out.println("++++++++++"+tStationMonthReport.getStationMonthReportId());
			sationmonthreportDAO.save(tStationMonthReport);
			return true;
		} catch (DAOException e) {
			
			e.printStackTrace();
			return false;
		}

	}

 dao层就不说了,到此完毕。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目录....................................................................................................................................................2 说明....................................................................................................................................................3 一、使用到的开发工具:.........................................................................................................3 二、服务端开发步骤.................................................................................................................3 1、使用xfire 创建Web 服务。..............................................................................................3 2、创建服务接口和实现.........................................................................................................7 3、xfire 服务配置....................................................................................................................9 4、服务发布...........................................................................................................................10 5、为服务配置安全认证.......................................................................................................11 三、客户端开发.......................................................................................................................12 1、新建Web 工程................................................................................................................. 12 2、导入xfire 包.....................................................................................................................13 3、创建类定义.......................................................................................................................15 四、扩展1-使用xfire 插件创建客户端代码........................................................................ 18 1、插件安装.............................................................................................................................18 2、使用已安装的插件进行客户端代码生成........................................................................ 20 4、编写调用代码,调用服务.............................................................................................. 24 五、扩展2-使用axis(这时是1-4 版本)创建客户端代码.................................................... 28 1、使用WSDL2Java 工具根据WSDL 生成客户端代码.................................................. 28 2、新建工程项目...................................................................................................................30 3、编写调用代码...................................................................................................................31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值