是“”的无参数构造函数;请求DTO”;ServiceStack中需要

本文关键字:DTO ServiceStack 请求 构造函数 参数 | 更新日期: 2023-09-27 18:23:57

是ServiceStack 中所需的"请求DTO"的无参数构造函数

如果我注释掉无参数约束

[DataContract]
[RestService("/Competitions/", "GET")]
[RestService("/Competitions/{Id}", "GET")]
public class Competitions
{
    [DataMember]
    public int CompetitionID { get; set; }
    [DataMember]
    public string CompName { get; set; }
    [DataMember]
    public string CompType { get; set; }
//public Competitions()
//{ 
//}
public Competitions(ABC abc)
    {
    this.CompetitionID = abc.abcID;
    this.CompName = abc.CompName;
    this.CompType = abc.CompType;
    }
}

访问元数据页面时,我会得到一个异常"No parameterless constructor servicestack"http://localhost/api/xml/metadata?op=Competitions

堆叠通道是

[External Code] 
    ServiceStack.DLL!ServiceStack.WebHost.Endpoints.Metadata.XmlMetadataHandler.CreateMessage(System.Type dtoType = {Name = "Competitions" FullName = "FSI.API.ServiceModel.Competitions"}) Line 17 + 0x8 bytes C#
    ServiceStack.DLL!ServiceStack.WebHost.Endpoints.Metadata.BaseMetadataHandler.ProcessOperations(System.Web.UI.HtmlTextWriter writer = {System.Web.UI.HtmlTextWriter}, ServiceStack.ServiceHost.IHttpRequest httpReq = {ServiceStack.WebHost.Endpoints.Extensions.HttpRequestWrapper}) Line 56 + 0xe bytes    C#
    ServiceStack.DLL!ServiceStack.WebHost.Endpoints.Metadata.BaseMetadataHandler.Execute(System.Web.HttpContext context = {System.Web.HttpContext}) Line 34 C#
    ServiceStack.DLL!ServiceStack.WebHost.Endpoints.Support.HttpHandlerBase.ProcessRequest(System.Web.HttpContext context = {System.Web.HttpContext}) Line 20   C#
[External Code] 

是“”的无参数构造函数;请求DTO”;ServiceStack中需要

XmlSerializer需要一个构造函数才能工作,如果需要,可以将其设置为内部、私有或受保护。