是ServiceStack中所需的"a Request 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;
}
}当访问元数据页面http://localhost/api/xml/metadata?op=Competitions时,我会得到一个异常"No parameterless constructor servicestack“
堆栈跟踪是
[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] 发布于 2012-02-10 22:42:20
XmlSerializer需要一个构造函数才能工作,您可以根据需要将其设置为内部的、私有的或受保护的。
https://stackoverflow.com/questions/9229226
复制相似问题