为什么 ToOptimizedResult 会抛出“请求的功能未实现".在单声道上? [英] Why does ToOptimizedResult throw "Requested feature is not implemented." on Mono?

查看:14
本文介绍了为什么 ToOptimizedResult 会抛出“请求的功能未实现".在单声道上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 构建我的 ServiceStack 4.0.8 服务.在 Windows 上一切正常,但是当我尝试在带有 NGINX 1.4.1 和 fastcgi-server4 的 Mono 2.10.8.1/Ubuntu 13.10 上运行时.

I am building my ServiceStack 4.0.8 service using Visual Studio. On Windows everything works perfectly, but when I try to run on Mono 2.10.8.1 / Ubuntu 13.10 with NGINX 1.4.1 and fastcgi-server4.

我得到一个例外:

请求的功能未实现.在 System.Web.HttpContextWrapper.GetService (System.Type serviceType) [0x00000] in :0在 ServiceStack.Host.RequestPreferences.GetWorker(System.Web.HttpContextBase 上下文)[0x00000] 中:0在 ServiceStack.Host.RequestPreferences.get_HttpWorkerRequest () [0x00000]在:0 在 ServiceStack.Host.RequestPreferences.get_AcceptEncoding () [0x00000]在:0 在 ServiceStack.Host.RequestPreferences.get_AcceptsDeflate () [0x00000]在 ServiceStack.RequestExtensions.GetCompressionType 的 :0 (IRequest 请求)[0x00000]在:0 在 ServiceStack.RequestExtensions.ToOptimizedResult[List1](IRequest 请求,System.Collections.Generic.List1 dto)[0x00000]在:0 在 Phase1HistoryServer.SymbolsService.Get(Phase1HistoryServer.Symbols 请求)[0x00000] 在:0

The requested feature is not implemented. at System.Web.HttpContextWrapper.GetService (System.Type serviceType) [0x00000] in :0 at ServiceStack.Host.RequestPreferences.GetWorker (System.Web.HttpContextBase context) [0x00000] in :0 at ServiceStack.Host.RequestPreferences.get_HttpWorkerRequest () [0x00000] in :0 at ServiceStack.Host.RequestPreferences.get_AcceptEncoding () [0x00000] in :0 at ServiceStack.Host.RequestPreferences.get_AcceptsDeflate () [0x00000] in :0 at ServiceStack.RequestExtensions.GetCompressionType (IRequest request) [0x00000] in :0 at ServiceStack.RequestExtensions.ToOptimizedResult[List1] (IRequest request, System.Collections.Generic.List1 dto) [0x00000] in :0 at Phase1HistoryServer.SymbolsService.Get (Phase1HistoryServer.Symbols request) [0x00000] in :0

如果我直接返回 DTO 对象,我不会收到错误.但是,如果我使用 base.Request.ToOptimizedResult 则会发生异常.

If I return the DTO object directly I do not get errors. However if I use base.Request.ToOptimizedResult the exception occurs.

List<DataItem> data = new List<DataItem>(); 
data.Add(new dataItem { Data = "fake data" });
return base.Request.ToOptimizedResult<List<DataItem>>(data);

推荐答案

更新:

已提交 ServiceStack,版本 4.0.16+ 不应受此异常影响的时间更长.

Update:

A commit to ServiceStack has been made, and version 4.0.16+ should no longer suffer from this exception.

ToOptimizedResult() 有效,这不是 ServiceStack 的缺点,而是 Mono 和 fastcgi-server-4 的缺点.有一个合适的解决方法.

ToOptimizedResult() works, this is not a shortcoming of ServiceStack but rather with Mono and fastcgi-server-4. There is a suitable workaround.

抛出这个异常是因为 Mono 项目还没有实现这个方法.由于 Mono 是一个开源项目,他们必须自己重新创建 .NET 规范,而这种方法根本没有完成.

This exception is thrown because the Mono project have not yet implemented this method. As Mono is an OpenSource project they have to recreate the .NET specification themselves, and this method simply isn't done.

有关 Mono 源代码,请参见此处:

public class HttpContextWrapper : HttpContextBase
{
    ...

    [MonoTODO]
    public override object GetService (Type serviceType)
    {
        throw new NotImplementedException ();
    }
}

单声道解决方案,使用自托管应用程序:

我在 Mono (尽管是 v3.2.6) 上运行 ServiceStack,使用 ToOptimizedResult 没有任何问题,但我不使用 fastcgi-server4,它将依赖于 System.Web.HttpContextWrapper.

Mono solution, use a Self Hosted Application:

I run ServiceStack on Mono (albeit v3.2.6) and don't have any problem using ToOptimizedResult but I don't use fastcgi-server4, which will relies on System.Web.HttpContextWrapper.

相反,我使用了一个自托管的 ServiceStack 应用程序,它基于底层 System.Net.HttpListener 池,它似乎不受相同问题的影响.因此效果很好.

Instead I use a self hosted ServiceStack application, which is based on a pool of underlying System.Net.HttpListener, which doesn't seem to be affected by the same issue. And thus works well.

以下是使用您的测试代码的自托管 ServiceStack 应用程序的代码:

Below is code for a working self-hosted ServiceStack application, using your test code:

using System;
using ServiceStack;
using System.Collections.Generic;

namespace Testv4
{
    class MainClass
    {
        public static void Main()
        {
            // Very basic console host
            var appHost = new AppHost(500);
            appHost.Init();
            appHost.Start("http://*:8082/");
            Console.ReadKey();
        }
    }

    public class AppHost : AppHostHttpListenerPoolBase
    {
        public AppHost(int poolSize) : base("Test Service", poolSize, typeof(TestApp).Assembly) {}

        public override void Configure(Funq.Container container)
        {
        }
    }

    public static class TestApp
    {
        public class DataItem
        {
            public string Data { get; set; }
        }

        [Route("/Test", "GET")]
        public class TestRequest {}

        public class TestController : Service
        {
            public object Get(TestRequest request)
            {
                var list = new List<DataItem> {
                    new DataItem { Data = "Fake Data" }
                };

                return base.Request.ToOptimizedResult(list);
            }
        }
    }
}

您可以通过转到 localhost:8082/Test 来测试应用程序.压缩结果时不应该抛出异常.

You can test the application by going to localhost:8082/Test. It shouldn't throw an exception when compressing the result.

我的建议是使用 NGINX 的透明代理功能将来自 NGINX 的请求转发到 ServiceStack 应用程序,或者干脆切断 NGINX 并将请求直接发送到应用程序.

My suggestion would be to either forward requests from NGINX using it's transparent proxying abilities onto the ServiceStack application, or simply cut out NGINX and have request go directly to the application.

AppHostHttpListenerPoolBase 运行良好,我在生产环境中使用它没有任何问题.

The AppHostHttpListenerPoolBase works well and I have had no issue using it in production environments.

这篇关于为什么 ToOptimizedResult 会抛出“请求的功能未实现".在单声道上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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