SOAP - Manual SOAP Calls
Even without ASMX or WCF proxies, you can call a SOAP service manually by crafting the XML request and posting it with HttpClient
(or HttpWebRequest
in older .NET).
Here’s a minimal example in C# that shows how to do this:
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var soapEnvelope = @"<?xml version=""1.0"" encoding=""utf-8""?>
<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/"">
<soap:Body>
<HelloWorld xmlns=""http://tempuri.org/"" />
</soap:Body>
</soap:Envelope>";
var url = "http://localhost/MyService.asmx";
var action = "http://tempuri.org/HelloWorld"; // SOAPAction from WSDL
using var client = new HttpClient();
var content = new StringContent(soapEnvelope, Encoding.UTF8, "text/xml");
content.Headers.Add("SOAPAction", action);
var response = await client.PostAsync(url, content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
Key Points:
-
SOAPAction header is required by many ASMX services to identify which method you’re calling.
-
The envelope format is strict — namespaces and casing must match what the service expects.
-
The response will be XML, so you’ll usually parse it with
XDocument
orXmlDocument
. -
This approach is completely independent of proxy generation — useful when you can’t or don’t want to import the WSDL.