I'm trying to deserialize an XML response but I can't seem to understand what is not working here
These are my classes (generated with the .NET developer tools)
[Serializable]
[XmlType(AnonymousType = true, Namespace = "http://www.crs.lombardia.it/schemas/DCSanita/GSSC/2007-01/calcolaIup/")]
[XmlRoot("GSSC.calcolaIupResponse", Namespace = "http://www.crs.lombardia.it/schemas/DCSanita/GSSC/2007-01/calcolaIup/", IsNullable = false)]
public partial class GSSCcalcolaIupResponse
{
private param1 paramField;
/// <remarks/>
[XmlElementAttribute(Namespace = "")]
public param1 param
{
get
{
return this.paramField;
}
set
{
this.paramField = value;
}
}
}
/// <remarks/>
[XmlType(AnonymousType = true)]
public partial class param1
{
private string iupField;
/// <remarks/>
public string iup
{
get
{
return this.iupField;
}
set
{
this.iupField = value;
}
}
}
The xml response is like this:
<m:GSSC.calcolaIupResponse xmlns:m="http://www.crs.lombardia.it/schemas/DCSanita/GSSC/2013-01/calcolaIup/">
<param>
<iup>0000W05RNF</iup>
</param>
</m:GSSC.calcolaIupResponse>
And here's the code for deserialization.
GSSCcalcolaIupResponse iup = new GSSCcalcolaIupResponse();
XmlSerializer serializer = new XmlSerializer(typeof(GSSCcalcolaIupResponse));
IUPDummyResponse retValue = new IUPDummyResponse();
using (TextReader reader = new StringReader(xml))
{
if (soapFault == null)
iup = (GSSCcalcolaIupResponse)serializer.Deserialize(reader);
}
The namespace in your class
GSSCcalcolaIupResponse
and namespace in your xml string are different. It is the reason. Just change to use the same namespace, it will fix the error: