为什么ServiceStack在初始加载后返回“任务已被处置”

时间:2013-12-27 17:15:59

标签: c# servicestack

我正在运行一个VS 2010项目,其中包含通过Nuget安装的最新4.0.5 ServiceStack。我正在将Durandal和SignalR混合在一起,但我不确定这是否会影响ServiceStack正在做的事情。我正在浏览每个OSS项目并设置每个项目的“Hello Worlds”。我的全部资料来源:

https://github.com/wtilton/DurandalServiceStackSignalR.git

https://github.com/wtilton/DurandalServiceStackSignalR

public class HelloService : Service
{
    public object Any(Hello request)
    {
        return new HelloResponse { Result = "Hello, " + request.Name };
    }
} 

[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello
{
    public string Name { get; set; }
}

public class HelloResponse
{
    public string Result { get; set; }
}

如果我第一次获得预期结果时导航到(本地)/ api / hello / World(或直接调用服务)。虽然第二次调用似乎爆炸了,因为它正在使用已关闭的Thread的任务。谁能给我一个线索是什么了?

堆栈跟踪:

    [ObjectDisposedException: The task has been disposed.]
   System.Threading.Tasks.Task.ThrowIfDisposed() +3544149
   System.Threading.Tasks.Task.ContinueWith(Action`1 continuationAction, TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, StackCrawlMark& stackMark) +47
   System.Threading.Tasks.Task.ContinueWith(Action`1 continuationAction) +44
   ServiceStack.Host.Handlers.HttpAsyncTaskHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +119
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9042404
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

更多代码:

    public class AppHost : AppHostBase
    {
        //Tell Service Stack the name of your application and where to find your web services
        public AppHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }

        public override void Configure(Funq.Container container)
        {
            GlobalHost.DependencyResolver = new FunqDependencyResolver(container); 
            SetConfig(new HostConfig { HandlerFactoryPath = "api" });

            //register any dependencies your services use, e.g:
            //container.Register<ICacheClient>(new MemoryCacheClient());
        }
    }


    protected void Application_Start()
    {
        RouteTable.Routes.MapHubs();
        AreaRegistration.RegisterAllAreas();

        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);

        new AppHost().Init();
    }

...

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
        routes.IgnoreRoute("api/{*pathInfo}");

        routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

这似乎与这个问题相似:ServiceStack and MVC4 not wiring up for Api return calls但是作者似乎无法找到修复,并且似乎没有积极参与这个问题。另一个区别是我得到这个错误,直接通过JS调用它或通过浏览器查看它。

1 个答案:

答案 0 :(得分:1)

我升级到框架4.5.1,这解决了问题。使用版本4也提供了最新的SignalR适配,因此升级似乎非常必要,以便使用最新和最好的。