I needed to do this myself and since I couldn't find any answers online, here's what I worked out. This uses a simple SOAP calculator service with an 'Add' method that takes two numbers and returns the sum.
public async Task<int> AddNumbersAsync(Uri uri, int a, int b)
var soapString = this.ConstructSoapRequest(a, b);
using (var client = new HttpClient())
var content = new StringContent(soapString, Encoding.UTF8, "text/xml");
using (var response = await client.PostAsync(uri, content))
var soapResponse = await response.Content.ReadAsStringAsync();
private string ConstructSoapRequest(int a, int b)
return String.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
</s:Envelope>", a, b);
private int ParseSoapResponse(string response)
var soap = XDocument.Parse(response);
XNamespace ns = "http://CalculatorService/";
var result = soap.Descendants(ns + "AddResponse").First().Element(ns + "AddResult").Value;
Great answer, please note that HttpClient is intended to be created once and reused for many requests with the same configuration. So I suggest that you create a static member and reuse it across multiple calls to your sample AddNumbersAsync
@Alireza Valid point. I was only using my code for testing some things so it didn't really matter in my case but for a more formal service that's certainly the right decision.