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

查看:132
本文介绍了为什么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]中的位置:: 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] 在:0处的ServiceStack.RequestExtensions.GetCompressionType(IRequest请求)[0x00000] 在0处在ServiceStack.RequestExtensions.ToOptimizedResult [List 1] (IRequest request, System.Collections.Generic.List 1 dto)[0x00000] :在0处的Phase1HistoryServer.SymbolsService.Get(在:0处的"Phase1HistoryServer.Symbols请求")[0x00000]

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是一个OpenSource项目,因此他们必须自己重新创建.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解决方案,请使用自托管应用程序:

我在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的请求转发到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天全站免登陆