I'm a running a wcf service and I'm calling this method
public static Estimate Pro_GetEstimate(int estimateID)
{
try
{
return GetDeserializedData<Estimate>("ESTIMATE", "<ESTIMATE><ID>0</ID><NAME>Estimate for stuff</NAME><DESCRIPTION>This estimate if for stuff</DESCRIPTION><ESTIMATETYPE>TOPDOWN</ESTIMATETYPE></ESTIMATE>");
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
}
This is the XML I'm sending. It's just for testing, it should came from a stored procedure.
<ESTIMATE><ID>0</ID><NAME>Estimate for stuff</NAME><DESCRIPTION>This estimate if for stuff</DESCRIPTION><ESTIMATETYPE>TOPDOWN</ESTIMATETYPE></ESTIMATE>
This is the class I deserialize it into
[DataContract]
public class Estimate
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string NAME { get; set; }
[DataMember]
public string DESCRIPTION { get; set; }
[DataMember]
public ESTIMATETYPE ESTIMATETYPE { get; set; }
}
I deserialize the XML just fine. I use this method
private static T GetDeserializedData<T>(string roottAttribute, string xmlToDeserialize) where T : new()
{
T deserializedData;
XmlSerializer eetXmlSerializer = new XmlSerializer(typeof(T), new XmlRootAttribute(roottAttribute));
using (StringReader stringReader = new StringReader(xmlToDeserialize))
using (XmlReader reader = XmlReader.Create(stringReader))
{
deserializedData = (T)eetXmlSerializer.Deserialize(reader);
}
return deserializedData;
}
Everything works just until it returns to the front end. Then I get the error mentioned in the title.
I read somewhere else that this could be a problem with enums.
I do have this enum
[DataContract]
public enum ESTIMATETYPE
{
[EnumMember]
TOPDOWN,
[EnumMember]
BOTTOMUP
}
But the funny thing is that if I send the XML with the ESTIMATETYPE empty, it works.
<ESTIMATE><ID>0</ID><NAME>Estimate for stuff</NAME><DESCRIPTION>This estimate if for stuff</DESCRIPTION><ESTIMATETYPE></ESTIMATETYPE></ESTIMATE>
I call the GetDeserializedData method with other XML and it works fine. I only get this error on this situation.
Any ideas??