JAVA—咖啡館

          ——歡迎訪問rogerfan的博客,常來《JAVA——咖啡館》坐坐,喝杯濃香的咖啡,彼此探討一下JAVA技術,交流工作經驗,分享JAVA帶來的快樂!本網站部分轉載文章,如果有版權問題請與我聯系。

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            447 Posts :: 145 Stories :: 368 Comments :: 0 Trackbacks
          今天終于把webservice搞完了,寫個總結,我是在原來的項目中,進行webservice擴展的。

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

             

           

          下一步

             

              接下來選擇xfire包

             

              finish 完成。

              這樣在你的項目中會產生xfire的工具包,這里完全可以自己將所需要的包放入lib下。

              由于我的原始項目是ssh的,這里就不再說了,接下來進行xfire配置。

              首先web.xml

           1  <!-- begin XFire 配置 -->
           2    <servlet>   
           3       <servlet-name>xfire</servlet-name>   
           4       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
           5    </servlet>   
           6    <servlet-mapping> 
           7       <servlet-name>xfire</servlet-name>
           8       <url-pattern>*.ws</url-pattern>
           9    </servlet-mapping>
          10    
          11 <!-- 配合Spring容器中XFire一起工作的Servlet-->  
          12   <servlet>
          13    <servlet-name>XFireServlet</servlet-name>
          14    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
          15  </servlet>
          16  <servlet-mapping>
          17    <servlet-name>XFireServlet</servlet-name>
          18    <url-pattern>/servlet/XFireServlet/*</url-pattern>
          19  </servlet-mapping>
          20  <servlet-mapping>
          21    <servlet-name>XFireServlet</servlet-name>
          22    <url-pattern>/services/*</url-pattern>
          23  </servlet-mapping>

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

                這里說說為什么定義窄接口,原因xfire會導出spring整個接口,不能控制那些暴露給用戶,這樣做就不會將所有接口暴露給用戶。

              下來說說,在項目下生成的services.xml,這個里面是按照spring2.0的命名空間配置的,所以改寫這個xml

              

           這樣就不會出錯了。

           這樣啟動Tomcat,如果啟動時拋以下異常,則刪掉發布后lib中的spring1.2版本,原因與spring2沖突

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

           服務器啟動后,在項目名后面鍵入/services 則出現wsdl,另存為即可。

           

           看看我的spring配置文件 ,和上面的xfire-servlet.xml對應起來。

           1<!-- webservice -->
           2    <bean id="iwebserviceTarget" class="com.seavision.huayi2.service.impl.WebserviceImpl">
           3         <property name="businsesslogDAO">
           4            <ref local="TBusinsessLogDAO"/>
           5        </property>
           6        <property name="sationmonthreportDAO">
           7            <ref local="TStationMonthReportDAO"/>
           8        </property>        
           9    </bean>
          10     <bean id="webservicesService" parent="txProxyTemplate">
          11        <property name="target" ref="iwebserviceTarget">
          12        </property>
          13    </bean>

           

              service即實現類如下,此代碼僅為本人項目代碼,僅供參考,切勿抄送

             

           1public interface IWebservice {
           2    /***************
           3     * 取得基礎數據表中所有數據,以基礎數據建立日期的倒敘排序(HY0703)
           4     * @throws DAOException 
           5     * ******************/

           6    public List<TBusinsessLog> getYeWuList();
           7    /*******************************
           8    *增加工作站月工作計劃信息
           9    ********************************/

          10    public boolean insertYueJiHua(TStationMonthReport tStationMonthReport);
          11}

          12

           

           實現類

           1public class WebserviceImpl implements IWebservice{
           2    TBusinsessLogDAO  businsesslogDAO;
           3    TStationMonthReportDAO    sationmonthreportDAO;
           4
           5    
           6    public TStationMonthReportDAO getSationmonthreportDAO() {
           7        return sationmonthreportDAO;
           8    }

           9
          10
          11    public void setSationmonthreportDAO(TStationMonthReportDAO sationmonthreportDAO) {
          12        this.sationmonthreportDAO = sationmonthreportDAO;
          13    }

          14
          15
          16    public TBusinsessLogDAO getBusinsesslogDAO() {
          17        return businsesslogDAO;
          18    }

          19
          20
          21    public void setBusinsesslogDAO(TBusinsessLogDAO businsesslogDAO) {
          22        this.businsesslogDAO = businsesslogDAO;
          23    }

          24
          25
          26    public List<TBusinsessLog> getYeWuList(){
          27        System.out.println("調用ok");
          28        String hql="from TBusinsessLog as t order by t.cretateDate desc";
          29        List<TBusinsessLog> list= new ArrayList<TBusinsessLog>();
          30        try {
          31            List blist=businsesslogDAO.find(hql);
          32            for(int i=0;i<blist.size();i++){
          33                list.add((TBusinsessLog) blist.get(i));
          34            }

          35        }
           catch (DAOException e) {
          36            // TODO Auto-generated catch block
          37            e.printStackTrace();
          38        }

          39        return list;
          40    }

          41    
          42    /*******************************
          43    *增加工作站月工作計劃信息
          44    ********************************/

          45    public boolean insertYueJiHua(TStationMonthReport tStationMonthReport) {    
          46        System.out.println("調用ok");
          47        try {
          48            System.out.println("++++++++++"+tStationMonthReport.getStationMonthReportId());
          49            sationmonthreportDAO.save(tStationMonthReport);
          50            return true;
          51        }
           catch (DAOException e) {
          52            
          53            e.printStackTrace();
          54            return false;
          55        }

          56
          57    }

          58


           dao層就不說了,到此完畢。

          posted on 2010-04-27 10:51 rogerfan 閱讀(2048) 評論(0)  編輯  收藏 所屬分類: 【開源技術】
          主站蜘蛛池模板: 兰考县| 穆棱市| 章丘市| 忻州市| 葵青区| 巨鹿县| 黄龙县| 台南市| 庆城县| 海伦市| 内江市| 贡山| 政和县| 尼勒克县| 莱州市| 原阳县| 那坡县| 陆丰市| 庄浪县| 富蕴县| 大石桥市| 大洼县| 图片| 永州市| 霍邱县| 台南市| 西华县| 射阳县| 共和县| 田东县| 大城县| 略阳县| 阜阳市| 喀什市| 监利县| 定日县| 海兴县| 汾阳市| 康定县| 奎屯市| 花莲县|