移植Windows自宿主WCF服務到Linux/Mono2.8

來源:互聯網
上載者:User

Windows服務是這些背景程式、後台服務的正規名詞。Windows服務的運行可以在沒有使用者幹預的情況下,在後台運行,沒有任何介面。通過Windows服務管理員進行管理。服務管理員也只能做些簡單的操作:開始,暫停,繼續,停止。Windows服務的特點:在後台運行,沒有使用者互動,可以隨Windows啟動而啟動。

後台服務在Unix/Linux上叫做Daemon,在Linux系統中就包含許多的Daemon。判斷Daemon最簡單的方法就是從名稱上看。Linux下自動啟動的服務都在/etc/rc.d/init.d/目錄下,比如說mysql。如果不想讓一個服務自動運行,把/etc/rc.d/init.d/目錄下的這個服務指令碼移除掉就可以(一定要移除嗎,不可以使用類似Window下的手動啟動?)。

可以操作的狀態:

  • start             啟動服務,等價於服務指令碼裡的start命令
  • stop             停止服務,等價於副外長指令碼stop命令
  • restart          關閉服務,然後重新啟動,等價於指令碼restart命令
  • reload          使服不重新啟動而重讀設定檔,等價與服務指令碼的reload命令
  • status           提供服務的目前狀態,等價於服務指令碼的status命令
  • condrestart  如果服務鎖定,則這個來關閉服務,然後再次啟動,等價於condrestart命令

Mono 下的Windows服務叫做mono-service,mono-service 運行.net 1.0 程式集 和用 mono-service2 運行.net  2.0 以上的程式集。mono 2.8已經不支援.net 1的程式了,所以我們現在都是使用mono-service2,命令列說明文檔參考http://manpages.ubuntu.com/manpages/lucid/man1/mono-service.1.html。

       -d:DIRECTORY
              Use this  option  to  specify  the  working  directory  for  the
              service.  The default is the current directory.

       -l:LOCKFILE
              Specifies the file to use for locking, the default is a filename
              constructed in /tmp based on the name of the program that  hosts
              the service.

       -m:MESSAGE
              Name to show in the syslog.

       -n:NAME
              Use  this  to specify the service to be launched (if the program
              contains more than one service).   The default  is  to  run  the
              first defined service.

       --debug
              Use  this  option to prevent mono-service from redirecting stdin
              and stdout and prevent the program to be sent to the background.
              Equivalent to --no-daemon

       --no-daemon
              Use  this  option to prevent mono-service from redirecting stdin
              and stdout and prevent the program to be sent to the background.
              Equivalent to --debug.

Mono 2.8對wcf的支援也比較好了,這裡的例子就是將Windows下self host的一個wcf服務移植到Linux上。

1、在Window下編寫一個WCF 服務端作為Window服務。我們服務的代碼結構如下

要將.NET程式移植到Mono,我們一般會使用net 應用遷移到Mono 工具 (Moma)檢查下相容性。下面這個項目的檢查結果,看看是不是Mono2.8完美支援WCF。

DynIPServiceWS是WCF的windows服務的宿主,我們把代碼放到Linux下使用MonoDevelop編譯.放到/home/geffzhang/Projects/DynIPServiceWS目錄下,切換到這個目錄,執行命令

mono-service DynIPServiceWS.exe
運行DynIPClient.exe,返回運行結果說明服務已經在運行,如果用戶端出現目標機器積極拒絕說明服務沒有啟動。
mono DynIPClient.exe。
關於Mono下的WCF的可以參考這個部落格,作者 寫了一個系列的文章:http://veritas-vos-liberabit.com/monogatari/
本文的例子下載:http://cid-33478a966734670f.office.live.com/self.aspx/.Public/WCF/DynIPUpdater%5E_0.1.zip
 
目前還有一個問題沒有解決,就是如何把mono-service封裝成Linux的Daemon,留待後續補充,歡迎有做好的同學共用下怎麼做? http://www.cnblogs.com/sjhrun2001/archive/2009/03/10/1408264.html
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.