SoapHttpClientProtocol Versus HttpWebRequest
<p>I'm doing some performance testing and ran across something puzzling to myself and I was hoping someone could shed some light.</p>

<p>I'm comparing the performance between an HttpWebRequest and a SoapHttpClientProtocol. In my tests I see the SoapHttpClientProtocol class performing twice as fast. However, I expected the HttpWebRequest to performance better.</p>

<p>Thanks for any insight anyone can provide!</p>

<p>Sam</p>

<p>Here is the code for the HttpWebRequest</p>

<pre><code>public string RetrieveValue()
{
    ASCIIEncoding encoding = new ASCIIEncoding();

    byte[] payload = encoding.GetBytes("sIP=");

    string Url = @"url/RetrieveValue";

    HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create(Url);
    wr.Method = "POST";
    wr.KeepAlive = false;
    wr.ContentType = "application/x-www-form-urlencoded";
    wr.ContentLength = payload.Length;
    wr.Timeout = 30000;

    HttpWebResponse webResponse;

    Stream wrStream = wr.GetRequestStream();

    wrStream.Write(payload, 0, payload.Length);
    wrStream.Close();

    webResponse = (HttpWebResponse)wr.GetResponse();

    Stream baseStream = webResponse.GetResponseStream();

    string result = null;

    using (StreamReader sr = new StreamReader(baseStream))
        result = sr.ReadToEnd();

    return result;
}
</code></pre>

<p>Here is the Code for the SoapHttpClientProtocol</p>

<pre><code>WebServiceBinding(Name = "Soap", Namespace = "http://namespace.com/")] 
public class MyRetriever : SoapHttpClientProtocol
{
    [SoapDocumentMethod("http://url.com/Retrieve", RequestNamespace = "http://url.com/", ResponseNamespace = "http://url.com/", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
    public string RetrieveValue(string sVal)
    {
        return (string)base.Invoke("RetrieveValue",
                                   new object[] { sVal })[0];
    }
}
</code></pre>
