I have this xml : Respuesta.xml
<ns1:PayOnLine_3pResponse xmlns:ns1="https://implementacion.nps.com.ar/ws">
<Respuesta p2:type="tns:RespuestaStruct_PayOnLine_3p" xmlns:p2="http://www.w3.org/2001/XMLSchema-instance">
<psp_ResponseCod p2:type="xsd:string">1</psp_ResponseCod>
<psp_ResponseMsg p2:type="xsd:string">EN CURSO - En Comercio</psp_ResponseMsg>
<psp_TransactionId p2:type="xsd:string">2502928</psp_TransactionId>
</Respuesta>
</ns1:PayOnLine_3pResponse>
And this Class: PayOnLine_3pResponse.cs
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = @"https://implementacion.nps.com.ar/ws")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = @"https://implementacion.nps.com.ar/ws", IsNullable = false)]
[System.ServiceModel.XmlSerializerFormatAttribute(Style = System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults = true)]
public partial class PayOnLine_3pResponse
{
[System.Xml.Serialization.XmlElementAttribute(Namespace = @"https://implementacion.nps.com.ar/ws")]
public Respuesta Respuesta { get; set; }
}
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "https://implementacion.nps.com.ar/ws")]
public partial class Respuesta
{
public string psp_ResponseCod { get; set; }
public string psp_ResponseMsg { get; set; }
public string psp_TransactionId { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute]
public string type { get; set; }
}
But, i can't deserialize it. The var obj are returning null
For example: Main.cs
var xml = File.ReadAllText("Respuesta.xml");
var obj = ToObject<PayOnLine_3pResponse>(xml);
private static T ToObject<T>(string xml)
{
if (string.IsNullOrEmpty(xml))
{
return default(T);
}
XmlSerializer serializer = new XmlSerializer(typeof(T));
XmlReaderSettings settings = new XmlReaderSettings();
using (StringReader textReader = new StringReader(xml))
{
using (XmlReader xmlReader = XmlReader.Create(textReader, settings))
{
return (T)serializer.Deserialize(xmlReader);
}
}
}
Anybody can help me? I have tried generate the class with svcutil, xsd... But with the same result. I can't deserialize data from xml to obj.
bellow you can see the dependencies and the target framework
"dependencies": {
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0",
"System.ServiceModel": "1.0.0",
"System.ServiceModel.Duplex": "4.0.1",
"System.ServiceModel.Http": "4.1.0",
"System.ServiceModel.NetTcp": "4.1.0",
"System.ServiceModel.Primitives": "4.1.0",
"System.ServiceModel.Security": "4.0.1",
"System.Private.ServiceModel": "4.1.0",
"System.Text.Encodings.Web": "4.0.0",
"System.Xml.XmlSerializer": "4.0.11",
"System.Xml.XDocument": "4.0.11",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}