您的位置:首页 > 运维架构 > Linux

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

2010-10-10 21:48 204 查看
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运行.net1.0程序集和用mono-service2运行.net2.0以上的程序集。mono2.8已经不支持.net1的程序了,所以我们现在都是使用mono-service2,命令行说明文档参考http://manpages.ubuntu.com/manpages/lucid/man1/mono-service.1.html。

-d:DIRECTORY
Usethisoptiontospecifytheworkingdirectoryforthe
service.Thedefaultisthecurrentdirectory.

-l:LOCKFILE
Specifiesthefiletouseforlocking,thedefaultisafilename
constructedin/tmpbasedonthenameoftheprogramthathosts
theservice.

-m:MESSAGE
Nametoshowinthesyslog.

-n:NAME
Usethistospecifytheservicetobelaunched(iftheprogram
containsmorethanoneservice).Thedefaultistorunthe
firstdefinedservice.

--debug
Usethisoptiontopreventmono-servicefromredirectingstdin
andstdoutandpreventtheprogramtobesenttothebackground.
Equivalentto--no-daemon

--no-daemon
Usethisoptiontopreventmono-servicefromredirectingstdin
andstdoutandpreventtheprogramtobesenttothebackground.
Equivalentto--debug.

Mono2.8对wcf的支持也比较好了,这里的例子就是将Windows下selfhost的一个wcf服务移植到Linux上。

1、在Window下编写一个WCF服务端作为Window服务。我们服务的代码结构如下





要将.NET程序移植到Mono,我们一般会使用net应用迁移到Mono工具(Moma)检查下兼容性。下面这个项目的检查结果,看看是不是Mono2.8完美支持WCF。





DynIPServiceWS是WCF的windows服务的宿主,我们把代码放到Linux下使用MonoDevelop编译.放到/home/geffzhang/Projects/DynIPServiceWS目录下,切换到这个目录,执行命令

mono-serviceDynIPServiceWS.exe

运行DynIPClient.exe,返回运行结果说明服务已经在运行,如果客户端出现目标机器积极拒绝说明服务没有启动。

monoDynIPClient.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,留待后续补充,欢迎有做好的同学共享下怎么做?/article/5920964.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: