【发布时间】:2015-05-08 08:00:23
【问题描述】:
我正在尝试使用 ServiceStack 3.9.17.0 实现 IAsyncService 接口。
这是我的服务定义的代码:
public class TestService : IAsyncService<int>
{
object IAsyncService<int>.ExecuteAsync(int request)
{
return "Yup that worked";
}
}
这是来自我的 Global.asax.cs 的代码:
public class Global : System.Web.HttpApplication
{
public class TestServiceAppHost : AppHostBase
{
public TestServiceAppHost() : base("Test Async Web Services", typeof(TestService).Assembly) { }
public override void Configure(Funq.Container container)
{
Routes.Add<int>("/Test");
}
}
}
当我运行并转到元数据页面时,我看到该项目中存在的其他 2 个服务仅实现了 IService(已删除以保持样本清洁),但我的 IAsyncService 不显示,如果我尝试点击它,我得到以下消息:
<Int32Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="">
<ResponseStatus>
<ErrorCode>KeyNotFoundException</ErrorCode>
<Message>The given key was not present in the dictionary.</Message>
<StackTrace>
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at ServiceStack.WebHost.Endpoints.Utils.FilterAttributeCache.GetRequestFilterAttributes(Type requestDtoType)
at ServiceStack.WebHost.Endpoints.EndpointHost.ApplyRequestFilters(IHttpRequest httpReq, IHttpResponse httpRes, Object requestDto)
at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName)
</StackTrace>
</ResponseStatus>
</Int32Response>
我们将不胜感激。
编辑:
根据mythz 的建议,我已将代码更新为如下所示(再次感谢您的回复)。
DTO 和服务:
[Route("/test")]
public class TestDTO
{
public int request { get; set; }
}
public class TestService : IAsyncService<TestDTO>
{
object IAsyncService<TestDTO>.ExecuteAsync(TestDTO request)
{
return "Yup that worked";
}
}
我让 Global.asax.cs 保持不变,只是我将路由更改为使用 DTO 并使路由小写以匹配 DTO 上的属性。我仍然有同样的问题。
编辑#2: 我升级到 v3.9.71 仍然遇到同样的问题。
【问题讨论】:
标签: c# servicestack servicestack-bsd