0

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??

Rui Martins
  • 2,164
  • 7
  • 33
  • 52
  • Have you read this previous SO post: http://stackoverflow.com/questions/5793504/wcf-catches-exception-the-server-did-not-provide-a-meaningful-reply – alan Jun 25 '14 at 17:42
  • Yes, that's where I read about the enums – Rui Martins Jun 25 '14 at 17:44
  • Enums are just integers. I guess your problem is related to the enum value being passed (TOPDOWN), which is obviously not a number and cannot be desserialized into one, but this is just a guess. Try replacing TOPDOWN with 1 and see if it works. Also, give explicit values to your enums (TOPDOWN = 0, BOTTOMUP = 1, for example) – rla4 Jun 25 '14 at 18:07

0 Answers0