ServiceStack.Metadata.BaseMetadataHandler.ProcessOperations的问题

时间:2015-01-14 06:28:07

标签: servicestack

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

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

[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。

1 个答案:

答案 0 :(得分:2)

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

您可以将Account响应DTO重命名为其他内容,例如:

public class AccountResponse
{
    ...
}

一般情况下,为了让您的服务使用者能够使用TypeScript和{{3},建议您为所有DTO指定唯一名称。它将所有DTO组合在一个命名空间下。此限制也可能适用于未来的语言。

相关问题