Reputation: 304
I have created a REST Web Service that in all other ways is working how I want it to work.
I have a main class that contains contacts, in that class, there are 2 other lists of classes that I have created. My main class, and one of the lists comes through the call with all information intact. However, the second class is comming through as empty. It has each item in the list, but each list item is empty.
Web Service Function
[OperationContract]
[WebGet(UriTemplate = "/Login/{IQPid}/{Password}")]
public IQP_Contacts Login(string IQPid, string password)
{
int iqpID = 0;
try
{
iqpID = int.Parse(IQPid);
}
catch { return null; }
IQP_Contacts contact = this.Repository.Contacts.Find(delegate(IQP_Contacts c) { return c.IqpID == iqpID; });
if (contact.Password == password)
{
return contact;
}
else return null;
}
Code calling the web service
WebClient proxy = new WebClient();
byte[] abc = proxy.DownloadData((new Uri("http://localhost:53468/IQP_Service.svc/Login/" + ID + "/" + password )));
Stream strm = new MemoryStream(abc);
DataContractSerializer obj = new DataContractSerializer(typeof(IQP_Contacts));
IQP_Contacts contact = (IQP_Contacts)obj.ReadObject(strm);
As you can see below, my webservice's class contains the information, but the the webpage does not
If anyone has any ideas, Please let me know. I am lost on this one. Something this simple shouldn't be this broken. Thanks
Upvotes: 0
Views: 1065
Reputation: 348
Check out the documentation about DataContractSerializer to see what does and does not get serialized by default: http://msdn.microsoft.com/en-us/library/cc656732.aspx
It is hard to tell without seeing your classes. But it is possible that your Files
property is readonly (only has a get
accesser with no set
) then it would not get serialized.
It could also depend on if you have selectively applied [DataContract]
/[DataMember]
attributes on your classes. This affects the behavior of what DataContractSerializer will serialize/deserialize. You would need to indicate that your "Files" property on IQP_RestWebService.Entitys.IQP_Contacts class is marked with a [DataMember] attribute and that you have a [DataContract] on the IQP_RestWebService.Entitys.Files class.
Upvotes: 3