我正在尝试使用 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>
任何和所有的帮助将不胜感激。
编辑:
在 myz 的建议后,我已将代码更新为如下所示(再次感谢您的回复)。
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 并且仍然遇到同样的问题。