title: Client to send SOAP request and receive response
body: <p>Trying to create a C# client (will be developed as a Windows service) that sends SOAP requests to a web service (and gets the results).</p>
  
  <p>From this <a href="https://stackoverflow.com/questions/1862965/sending-and-receiving-soap-xml">question</a> I saw this code:</p>
  
  <pre><code>protected virtual WebRequest CreateRequest(ISoapMessage soapMessage)
  {
      var wr = WebRequest.Create(soapMessage.Uri);
      wr.ContentType = "text/xml;charset=utf-8";
      wr.ContentLength = soapMessage.ContentXml.Length;
  
      wr.Headers.Add("SOAPAction", soapMessage.SoapAction);
      wr.Credentials = soapMessage.Credentials;
      wr.Method = "POST";
      wr.GetRequestStream().Write(Encoding.UTF8.GetBytes(soapMessage.ContentXml), 0, soapMessage.ContentXml.Length);
  
      return wr;
  }
  
  public interface ISoapMessage
  {
      string Uri { get; }
      string ContentXml { get; }
      string SoapAction { get; }
      ICredentials Credentials { get; }
  }
  </code></pre>
  
  <p>Looks nice, anyone knows how to use it and if it is the best practice?</p>