c# - 为什么自托管服务在处理一个在 Mono 上运行的响应后会挂起?

标签 c# wcf mono

我在使用简单的自托管 WCF 服务时遇到问题,在 Mono 上使用基本的 HTTP 绑定(bind)。当我在 .NET 上运行该服务时,一切正常。当我在 Mono 上运行服务器时,第一个请求工作正常,但第二个请求挂起,最终超时。

为了测试,我在 Windows 和 Mono 上运行服务器,并从在 Mono 上运行的客户端发出两个请求。当服务在 Windows 上运行时,HTTP 流看起来像我期望的那样:

POST /Echo HTTP/1.1 -->
<-- HTTP/1.1 100 Continue
POST /Echo HTTP/1.1 -->
<-- HTTP/1.1 100 Continue

不过,在 Mono 上,它看起来像这样:

POST /Echo HTTP/1.1 -->
<-- HTTP/1.1 100 Continue
<-- HTTP/1.1 200 OK
POST /Echo HTTP/1.1 -->

在达到默认的 60 秒超时并且客户端向服务器发送 FIN 之前,网络上没有其他事件。

我在下面包含了配置信息和代码。提前致谢。

配置

这是 mono --version 的输出:

Mono JIT compiler version 2.4.2.3 (Debian 2.4.2.3+dfsg-2~dhx1~jaunty1)
Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC)
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none

代码

服务

using System;
using System.ServiceModel;

namespace Sample.Echo
{
    [ServiceContract]
    public interface IEchoService
    {
        [OperationContract]
        string Echo(string val);
    }

    public class EchoService : IEchoService
    {
        public string Echo(string val)
        {
            return val ?? String.Empty;
        }
    }
}

服务器

using System;
using System.ServiceModel;
using Sample.Echo;

namespace Sample.Echo.Server
{
    class Program
    {
        static void Main(string[] args)
        {
            string addr = "http://localhost:9999/";
            if (args.Length > 0)
            {
                addr = args[0];
            }
            var host = new ServiceHost(typeof(EchoService));
            host.AddServiceEndpoint(typeof(IEchoService), new BasicHttpBinding(), addr + "Echo");
            host.Open();

            Console.Write("Press any key to end...");
            Console.ReadKey();
            Console.WriteLine("terminated");
            host.Close();
        }
    }
}

客户端

using System;
using System.ServiceModel;

using Sample.Echo;

namespace Sample.Echo.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            string addr = "http://localhost:9999/";
            if (args.Length > 0)
            {
                addr = args[0];
            }
            var client = new ChannelFactory<IEchoService>(new BasicHttpBinding(), addr + "Echo");
            var echoServ = client.CreateChannel();

            Console.WriteLine("Enter text to echo, or \"quit\" to quit.\n");
            int count = 0;
            while (true) 
            {
                string line = Console.ReadLine();
                if (line == null || line.ToLower().Equals("quit")) break;
                string response = echoServ.Echo(line);
                Console.WriteLine("{0}: {1} => {2}", ++count, line, response);
            }
        }
    }
}

最佳答案

您介意测试我们的 Mono 2.6 预览包吗?

WCF 在 Mono 2.4 中不是很强大,它只是作为预览发布。

关于c# - 为什么自托管服务在处理一个在 Mono 上运行的响应后会挂起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1875336/

相关文章:

c# - Linux Mono + Postsharp + Log4Net = 没有自动异常捕获

c# - 这是设计模式吗?

c# - wcf https ssl 中的服务端点出错。找不到与具有绑定(bind) WebHttpBinding 的端点的方案 http 匹配的基址

wcf - .Net Core 不支持 WSHttpBinding

c# - IIS 应用程序池管理和最佳实践

linux - 如何在 Linux 中使用 SHA256 对 EXE 进行签名?

ios - 无法从 CMSampleBuffer 获取图像元

c# - 删除 Split View中的单选按钮图标 Windows 通用应用程序

c# - 应用 Dijkstra 算法实现时列表中的对象被删除

c# - 从 ASPX/C# 页面发送 APNS,使用 SSL 进行身份验证