前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >移植Windows自宿主WCF服务到Linux/Mono2.8

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

作者头像
张善友
发布2018-01-19 16:32:48
1.2K0
发布2018-01-19 16:32:48
举报

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服务。我们服务的代码结构如下

image
image

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

image
image

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2010-10-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档