I’m new to RestSharp. And I use it in my Windows Phone 7.1 project.
I have a class UserProfile:
public class UserProfile
{
public string UserId {get; set}
public string Phone {get; set}
public string Email {get; set}
public string Firstname {get; set}
public string Lastname {get; set}
public bool Sex {get; set}
public string Status {get; set}
public DateTime CreatedDate {get; set}
public string Online {get; set}
public string Role {get; set}
public string AppId {get; set}
public string AppName {get; set}
public string Token {get; set}
}
I use RestSharp to send Http Request and receive response with XML format (corresponding with UserProfile class). How can I deserialize response content to UserProfile?
This is my code:
RestClient client = new RestClient("http://myaddress");
RestRequest request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Xml;
//...
//add parameters
//...
client.ExecuteAsync<UserProfile>(request, (response) => // <--------- right?
{
try
{
MessageBox.Show(response.Content); //returned content is correct
DotNetXmlDeserializer des = new DotNetXmlDeserializer();
//UserProfile up = des.Deserialize<UserProfile>(... <------- HOW ?
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
});
Please notice that there is no System.Xml.Serialization.XmlSerializer in Windows Phone.
Thank you!
Just use the
response.Data, that is the deserialized object!