Supposing that you want to invoke the following method:
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
[WebMethod]
public string HelloWorld(Foo foo)
{
return "Hello World";
}
You need to construct the correct SOAP envelope:
using (WebClient client = new WebClient())
{
client.Headers.Add("SOAPAction", "\"http://tempuri.org/HelloWorld\"");
client.Headers.Add("Content-Type", "text/xml; charset=utf-8");
var payload = @"<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><soap:Body><HelloWorld xmlns=""http://tempuri.org/""><foo><Id>1</Id><Name>Bar</Name></foo></HelloWorld></soap:Body></soap:Envelope>";
var data = Encoding.UTF8.GetBytes(payload);
var result = client.UploadData("http://example.com/Service1.asmx", data);
Console.WriteLine(Encoding.Default.GetString(result));
}
And parse the resulting XML.