title: Create a SOAP request manually without using a Service Reference
body: <p>So I know that the standard advice when utilizing a third parties web services is to add a Service Reference and create/use the generated proxy classes.</p>
  
  <p>I've actually done that and for the most part it works as it should. The issue that I'm running into is more specific to the way things are set up on the other parties end.</p>
  
  <p>The process that I need to go through is essentially this: <em>LogIn</em> -> <em>GetNumber</em></p>
  
  <p>Right now I can successfully log in but as soon as I try to call <em>GetNumber</em> I get a response back saying "The Log In context is NULL". This is a message from their end and is a result of the memory of the session immediately being lost.</p>
  
  <p>A session cookie needs to be maintained for all requests but the generated proxy for their SOAP services has no way of accessing that cookie. The reason there's no way to access that cookie is because they made the choice to use the SOAP transport to pass a piece of data back to the caller.</p>
  
  <p>So this puts me in a tough situation. I can either get them to change things on their end (maybe possible but only somewhat likely) or just not use the generated code and build the SOAP request manually.</p>
  
  <p>The problem is that I'm having a hard time finding any info on how to actually build the request manually because any time anybody asks how to do that the advice they get is to add a Service Reference and do it that way.</p>
  
  <p>As of right now I have:</p>
  
  <pre><code>        var cookieContainer = new CookieContainer();
          var handler = new HttpClientHandler()
          {
              CookieContainer = cookieContainer
          };
          var client = new HttpClient(handler);
  </code></pre>
  
  <p>Which I'm hoping to use to store the session cookie for the following request.</p>
  
  <p>Then I've started to try and construct the header of the request like:</p>
  
  <pre><code>        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("their end point");
  
          request.Method = "POST";
          request.Headers.Add("SOAPAction: \"\" ");
          request.ContentType = "text/xml; charset=utf-8";
  </code></pre>
  
  <p>but that doesn't feel quite right. Ultimately what I want is for that request to be something like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soap:Envelope 
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;soap:Body&gt;
                  &lt;login&gt;
                          &lt;userId&gt;coolUserId&lt;/userId&gt;
                          &lt;password&gt;coolPassword&lt;/password&gt;
                  &lt;/login&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>From there I'm assuming I'll get back a request that I can parse out and carry on with my life. Is this more or less right?</p>
  
  <p>If anybody has any insight on this or resources that could be helpful I would be very much appreciative!</p>