2015-01-14 63 views
0

我得到了我的Servicestack服務訪問操作時,下面的錯誤序列包含一個以上的匹配元素問題與ServiceStack.Metadata.BaseMetadataHandler.ProcessOperations

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

什麼給?我如何解決這個問題?

每個請求

[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; } 
} 

他們在不同的命名空間請求DTO。一個是Models.Account,另一個是ViewModels.Account。

+0

你的'Account' Request + Response DTO是什麼樣的? – mythz

回答

2

問題是因爲您的RequestResponse DTO類型名稱需要唯一命名。

它將工作的您重新命名Account響應DTO到別的東西,如:

public class AccountResponse 
{ 
    ... 
} 

一般來說它推薦給所有的DTO的,因爲它在訂單的需要爲您服務的消費者是被唯一命名能夠使用TypeScriptF# ServiceStack Reference,它們將單個命名空間下的所有DTO組合在一起。這一限制很可能適用於未來的語言。