ServiceStack.Metadata.BaseMetadataHandler.ProcessOperations 的问题

Issue with ServiceStack.Metadata.BaseMetadataHandler.ProcessOperations

我收到以下错误序列包含多个匹配元素

访问我的 Servicestack 服务中的操作时。 (URL: /json/metadata?op=账户)

[InvalidOperationException: Sequence contains more than one matching element]
   System.Linq.Enumerable.Single(IEnumerable`1 source, Func`2 predicate) +329
   ServiceStack.Metadata.BaseMetadataHandler.ProcessOperations(HtmlTextWriter writer, IRequest httpReq, IResponse httpRes) +260
   ServiceStack.Metadata.BaseMetadataHandler.ProcessRequest(IRequest httpReq, IResponse httpRes, String operationName) +116
   ServiceStack.Host.Handlers.<>c__DisplayClass1.<CreateProcessRequestTask>b__0() +77
   System.Threading.Tasks.Task.InnerInvoke() +42
   System.Threading.Tasks.Task.Execute() +61

[AggregateException: One or more errors occurred.]
   System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) +45
   System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) +111
   System.Threading.Tasks.Task.Wait() +11
   ServiceStack.Host.Handlers.HttpAsyncTaskHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +35
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +100

什么给了?我该如何解决这个问题?

每个请求的请求 DTO

    [Route("/account/{Id}", Notes = "Updates the details of the account whose id is provided", Summary = "Updates account details.", Verbs = "PUT")]
    [Route("/accounts", Notes = "Creates an account with the details provided.", Summary = "Creates an account.", Verbs = "POST")]
    [Route("/account/{Id}", Notes = "Deletes the account whose id is provided.", Summary = "Deletes an account.", Verbs = "DELETE")]
    [Route("/accounts/{Id}", Notes = "Returns the details of the account whose id is provided", Summary = "Returns account details.", Verbs = "GET")]
    [Api(Description = "Update, create or delete account with the details specified.")]
    public class Account
    {
        [ApiMember(Description = "The unique id of the account.")]
        public int Id { get; set; }

        [ApiMember(Description = "The id of the user who owns the account.")]
        public int? OwnerId { get; set; }

        [ApiMember(Description = "The account number being registered.")]
        public string Number { get; set; }

        [ApiMember(Description = "The type of the account. User created accounts default to bank accounts.")]
        public Constants.AccountType? Type { get; set; }

        [ApiMember(Description = "Defines the types of transactions for which the account may be used.")]
        public Constants.AccountPurpose? Purpose { get; set; }

        [ApiMember(Description = "The currency of the account.")]
        public Constants.Currency? Currency { get; set; }

        [ApiMember(Description = "The institution number of the Bank that provided the account number.")]
        public string InstitutionNumber { get; set; }

        [ApiMember(Description = "The transit tnumber of the branch that provided the account number.")]
        public string TransitNumber { get; set; }

        [ApiMember(Description = "Indicates whether the account holder signed a PAD agreement that allows automated withdrawals for bill payments.")]
        public bool? IsPadAccount { get; set; }
    }

和响应 DTO

public class Account
{
    public int Id { get; set; }

    public User Owner { get; set; }

    public User Creator { get; set; }

    public Client Client { get; set; }

    public string Number { get; set; }

    public Constants.AccountType Type { get; set; }

    public Constants.AccountPurpose Purpose { get; set; }

    public Constants.Currency Currency { get; set; }

    public DateTime DateCreated { get; set; }

    public Constants.AccountStatus Status { get; set; }

    public string InstitutionNumber { get; set; }

    public string TransitNumber { get; set; }

    public bool IsPadAccount { get; set; }
}

它们在不同的命名空间中。一个是 Models.Account 另一个是 ViewModels.Account.

问题是因为您的 RequestResponse DTO 类型名称需要唯一命名。

如果您将 Account 响应 DTO 重命名为其他名称,它将起作用,例如:

public class AccountResponse
{
    ...
}

一般来说,建议对所有 DTO 进行唯一命名,因为这是必需的,以便您的服务使用者能够使用 TypeScript and F# ServiceStack Reference,它将所有 DTO 组合在一个命名空间下。此限制也可能适用于未来的语言。