I am trying to return below model from my api method but it is returning empty reponse.
[DataContract]
public class MasterData
{
public IEnumerable<PROFILE> lstProfile { get; set; }
public IEnumerable<COMPETENCE> lstCOMPETENCE { get; set; }
public IEnumerable<TB> lstTB { get; set; }
public MasterData() { }
}
Response :
<MasterData xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WB.Q.Models"/>
When I am debugging web api method I can see the response properly formed at return statement,but I am not getting it as response
Action
[HttpGet]
[Route("api/Common/AllMasterData")]
public MasterData GetAllMasterData()
{
MasterData mstrData=new MasterData();
mstrData = Helper.GetAllMasterData();
return mstrData;
}
Helper method
internal static MasterData GetAllMasterData()
{
MasterData masterData = new MasterData();
DataSet ds = DBHelper.GetData("aaa", null);
List<COMPETENCE> lstCompetence = new List<COMPETENCE>();
if (ds != null && ds.Tables.Count > 0)
{
foreach (DataRow drow in ds.Tables[0].Rows)
{
Adding in list
}
}
masterData.lstCOMPETENCE = lstCompetence;
ds = DBHelper.GetData("bbb", null);
List<PROFILE> lstPROFILE = new List<PROFILE>();
if (ds != null && ds.Tables.Count > 0)
{
foreach (DataRow drow in ds.Tables[0].Rows)
{
Adding in list
}
}
masterData.lstProfile = lstPROFILE;
ds = DBHelper.GetData("zzz", null);
List<TBSite> lstTBSite = new List<TBSite>();
if (ds != null && ds.Tables.Count > 0)
{
foreach (DataRow drow in ds.Tables[0].Rows)
{
Adding in list
}
}
masterData.lstTBSite = lstTBSite;
return masterData;
}
If I remove DataContract from Modal, I am getting below error:
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
Is it mandatory to use DataContract and DataMember if we have collection of object as a property?