在linux上托管WCF服务

sat*_*230 9 mono wcf wine centos mod-mono

有没有办法在Linux上托管WCF服务.我读到了关于葡萄酒但我没有看到任何托管WCF服务的例子.

PS:我尝试过mono和mod_mono,但无济于事.

小智 19

您可以在独立的控制台应用程序中托管它,如下所示:

using System;
using System.ServiceModel;
using Service;

namespace Host
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("WCF Host!");
            var binding = new BasicHttpBinding ();
            var address = new Uri ("http://localhost:8080");
            var host = new ServiceHost (typeof(GreeterWcfService));
            host.AddServiceEndpoint (
                typeof(IGreeterWcfService), binding, address);
            host.Open ();

            Console.WriteLine ("Type [Enter] to stop...");
            Console.ReadLine ();
            host.Close ();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

GreeterWcfServiceWCF服务类本身在哪里,IGreeterWcfService是服务合同.

GitHub中的完整工作示例解决方案 - 包含服务,托管和客户端的单独项目.看看这个.