3
I made a call through my web api and put in a class. How I display the values?
xml:
<result>
<resourceName>activity</resourceName>
<size>1</size>
<entries>
<entry id="1802274" link="/activity/1802274.xml"/>
</entries>
</result>
taken the xml:
public class PegaVisita
{
HttpClient client;
Uri usuarioUri;
public async System.Threading.Tasks.Task GeraLocalAsync()
{
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.umov.me");
HttpResponseMessage response = client.GetAsync("CenterWeb/api/meutoken/activity.xml?description=Cancelar&Coletas").Result;
string tarefa = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var buffer = Encoding.UTF8.GetBytes(tarefa);
using (var stream = new MemoryStream(buffer))
{
var serializer = new XmlSerializer(typeof(Result));
var Teste = (Result)serializer.Deserialize(stream);
}
usuarioUri = response.Headers.Location;
}
}
}
catch (Exception ex)
{
Console.Write("Erro ao cadastrar os locais");
Console.Write("Error : " + ex.Message);
}
}
}
class that receives xml
namespace WsCliMotoristas
{
[Serializable]
[XmlRoot("result"), XmlType("rstult")]
public class Result
{
[XmlElement("resourceName")]
public string resourceName { get; set; }
[XmlElement("size")]
public string size { get; set; }
}
}
I don’t fall for any Ecstasy, you’re doing everything backwards. I just need to know how to redeem the values of the classes, display them or save them in the bank, for example
The Xmltype class is correct? It is "rstult", it should not be "result"?
– João Martins
Include this information by editing your original question and delete this.
– Leandro Angelo
Possible duplicate of deserialize xml
– Leandro Angelo
In addition to the misstype you are also not Rializando the elmento
<entries>
and its type<entry>
– Leandro Angelo
I fixed the error of the result, the Ntries I didn’t want to serialize anyway
– João Paulo Silva
[Xmlelement("Entries")] public Object Entries { get; set; } I’ve added it now
– João Paulo Silva
I don’t get any errors. I wanted to be able to visualize the content deserialized
– João Paulo Silva
Tried to put a breakpoint?
– Leandro Angelo