在 Linux 上托管 WCF 服务 [英] Hosting WCF service on linux

查看:14
本文介绍了在 Linux 上托管 WCF 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Linux 上托管 WCF 服务.我阅读了有关 wine 的信息,但没有看到任何使用它托管 WCF 服务的示例.

Is there Any way of hosting WCF service on Linux. I read about wine but i didn't see any example of hosting WCF service with it.

P.S : 我尝试过 mono 和 mod_mono 但无济于事.

P.S : I have tried mono and mod_mono but to no avail.

推荐答案

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

You can host it in a stand-alone console application like so:

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 ();
        }
    }
}

其中 GreeterWcfService 是 WCF 服务类本身,IGreeterWcfService 是服务协定.

Where GreeterWcfService is the WCF service class itself and IGreeterWcfService is the service contract.

GitHub 中的完整工作示例解决方案 - 带有单独的服务项目,托管和一个客户.看看吧.

Full working example solution in GitHub - with separate projects for the service, the hosting and a client. Check it out.

这篇关于在 Linux 上托管 WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆