I send a RestRequest and receive the response in xml format. This is my code:
class Employee
{
int id;
string name;
}
private void reqEmployee(Employee empl)
{
var client = new RestClient(ConfigurationManager.AppSettings["base_url"] + "/" +
ConfigurationManager.AppSettings["provider"] + "/" +
ConfigurationManager.AppSettings["serviceName"])
{
Timeout = -1
};
var request = new RestRequest(Method.POST);
var authenticationString = string.Format("{0}:{1}", ConfigurationManager.AppSettings["serviceUser"], ConfigurationManager.AppSettings["servicePass"]);
var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(authenticationString));
request.AddHeader("Authorization", "Basic " + base64EncodedAuthenticationString);
request.AddHeader("Content-Type", "text/plain");
var body = @"<GetEmployee xmlns=""http://test.dev.com/"">"
+ "\n" + @" <Id>" + empl.idno + "</Id>"
+ "\n" + @"</GetEmployee>";
request.AddParameter("text/plain", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
}
Example of the request I send:
<GetEmployee xmlns="http://test.dev.com/">
<Id>4132</Id>
</GetEmployee>
Example of the response I receive (response.Content
):
<GetEmployeeResponse xmlns="http://test.dev.com/">
<PropertyStatus xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Employee>
<Name>John</Name>
<Id>6584</Id>
</Employee>
<Employee>
<Name>Chris</Name>
<Id>4120</Id>
</Employee>
</PropertyStatus>
</GetEmployeeResponse>
How can I fill a List<Employee>
with response.Content
?