【问题标题】:ServiceStack FallbackRoute failing with upgraded ServiceStack versionServiceStack FallbackRoute 因升级的 ServiceStack 版本而失败
【发布时间】:2018-07-10 08:09:26
【问题描述】:

我们将 C# Web 服务从 ServiceStack V4.0.31 升级到 V5.1.0。我们在具有 monodevelop 运行时的 linux 环境中使用以下包。

  <package id="ServiceStack" version="5.1.0" targetFramework="net45" />
  <package id="ServiceStack.Client" version="5.1.0" targetFramework="net45" />
  <package id="ServiceStack.Common" version="5.1.0" targetFramework="net45" />
  <package id="ServiceStack.Interfaces" version="5.1.0" targetFramework="net45" />
  <package id="ServiceStack.Redis" version="5.1.0" targetFramework="net45" />
  <package id="ServiceStack.Text" version="5.1.0" targetFramework="net45" />

升级后,我们现在在处理一些客户请求时遇到了问题。我们的请求 DTO 包含多个路由,但以下一个总是失败。

[FallbackRoute("/{Path*}")]
public class S3Request : IRequiresRequestStream {
        public Stream RequestStream { get; set; }
}

当客户端发出一个

GET http://endpoint:1310/name/clients/C1/sites/G1 

(端口和路由无关紧要,只是示例)。我们收到一个 400 Bad Request 并带有以下错误响应。

{
  "ResponseStatus": {
    "ErrorCode": "ArgumentException",
    "Message": "Could not find property Path on S3Request",
    "StackTrace": "  at ServiceStack.Host.RestPath.CreateRequest (System.String pathInfo, System.Collections.Generic.Dictionary`2[TKey,TValue] queryStringAndFormData, System.Object fromInstance) [0x000c9] in <629ec152372546cf812fe4a698c7a784>:0 \n  at ServiceStack.Host.RestHandler.CreateRequest (ServiceStack.Web.IRequest httpReq, ServiceStack.Web.IRestPath restPath, System.Collections.Generic.Dictionary`2[TKey,TValue] requestParams, System.Object requestDto) [0x0001e] in <629ec152372546cf812fe4a698c7a784>:0 \n  at ServiceStack.Host.ServiceController+<>c__DisplayClass26_0.<RegisterService>b__0 (ServiceStack.Web.IRequest req) [0x00035] in <629ec152372546cf812fe4a698c7a784>:0 \n  at ServiceStack.Host.Handlers.ServiceStackHandlerBase.GetCustomRequestFromBinder (ServiceStack.Web.IRequest httpReq, System.Type requestType) [0x00018] in <629ec152372546cf812fe4a698c7a784>:0 \n  at ServiceStack.Host.RestHandler.CreateRequestAsync (ServiceStack.Web.IRequest httpReq, ServiceStack.Web.IRestPath restPath) [0x00017] in <629ec152372546cf812fe4a698c7a784>:0 \n  at ServiceStack.Host.RestHandler+<ProcessRequestAsync>d__14.MoveNext () [0x00125] in <629ec152372546cf812fe4a698c7a784>:0 "
  }
}

在下面的代码区域抛出异常的方法ServiceStack.Host.RestPath.CreateRequest(…)

for (int i = 0; i < this.TotalComponentsCount; i++) {
        string text = this.variablesNames [i];
        string key;
        if (text == null) {
                num++;
        } else if (!this.propertyNamesMap.TryGetValue (text.ToLower (), out key)) {
                if (!StringExtensions.EqualsIgnoreCase (Keywords.Ignore, text)) {
                        throw new ArgumentException ("Could not find property " + text + " on " + UrlExtensions.GetOperationName (this.RequestType));
                }

似乎 CreateRequest 方法希望 propertyNamesMap 有一个路由条目,但它不存在。我们想知道 V5.1.0 API 是否需要我们执行某种在 V4.0.31 中不需要的路径注册逻辑?

【问题讨论】:

    标签: c# servicestack


    【解决方案1】:

    您的 DTO 缺少 Request DTO 上的 Path 属性,Route 上的每个变量({ignore} 除外)都需要匹配 Request DTO 上的属性。

    【讨论】:

    • 多年来,我有相同的结构,但没有 Path 属性,它在 V5 升级之前就可以工作。一定是V5的变化!感谢您的回答,它有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多