Question: How do you Deserialize XML String into a C# Object in Asp.Net Core 3.1?
Please Login to see the rest of the answer
public async Task<POCOModelClass> callWebService()
{
var client = new RestClient("urlHere");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "text/xml");
//This is the payload if required
request.AddParameter("text/xml", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <soap:Body>\r\n <EnclosedBody xmlns=\"https://DomainName.com/\">\r\n <param1>SomeParam</param1>\r\n <param2>SomeParam</param2>\r\n <param3>SomeParam</param3>\r\n </EnclosedBody>\r\n </soap:Body>\r\n</soap:Envelope>", ParameterType.RequestBody);
IRestResponse response = await client.ExecuteAsync(request);
var serializer = new XmlSerializer(typeof(POCOModelClass));
POCOModelClass result;
using (TextReader reader = new StringReader(response.Content.ToString()))
{
result = (POCOModelClass)serializer.Deserialize(reader);
}
return result;
}