title: 500 Internal Server Error when accessing web service from c#
body: <p>I have been stumped on this problem for quite some time now. I am trying to create a SOAP request based on the information from a WSDL file to send to a web service and retrieve a response. From what I've read online this should be a fairly straight forward process, and all tutorials and guides have been almost the same.</p>
  
  <p>Code:</p>
  
  <pre><code>string message = @"&lt;?xml version=""1.0"" encoding=""utf-8""?&gt;
              &lt;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/""&gt;
                  &lt;soap:Body&gt;
                      &lt;GetQuote xmlns=""http://www.webservicex.net/""&gt;       
                          &lt;symbol&gt;BB&lt;/symbol&gt;        
                      &lt;/GetQuote&gt;  
                  &lt;/soap:Body&gt;
              &lt;/soap:Envelope&gt;";
  
          HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(@"http://www.webservicex.net/stockquote.asmx");
          webRequest.Headers.Add(@"SOAPAction:http://www.webservicex.net/GetQuote");
          webRequest.ContentType = "text/xml;charset=\"utf-8\"";
          webRequest.Method = "POST";
  
          XmlDocument soapEnvelopeXml = new XmlDocument();
          soapEnvelopeXml.LoadXml(message);
  
          using (Stream stream = webRequest.GetRequestStream())
          {
              soapEnvelopeXml.Save(stream);
          }
  
          using (WebResponse response = webRequest.GetResponse())
          {
              using (StreamReader rd = new StreamReader(response.GetResponseStream()))
              {
                  string soapResult = rd.ReadToEnd();
                  Console.WriteLine(soapResult);
              }
          }
  </code></pre>
  
  <p>I must not be clear on how this all works, to my understanding the http request is sent to the web service that we specify in the WebRequest.Create() method along with some other information like the SOAPAction which im guessing is the actual method we want to invoke? In the body of the message the xml namespace is linked and the elements have access through that namespace (GetQuote, symbol). So to me everything sounds like it should flow. There must be something I am missing or doing incorrectly because I am getting an internal server error when I try to read the response. </p>
  
  <p>I am trying to access a very basic web service from www.webservicex.com. The links are provided below.</p>
  
  <p>Service Link: <a href="http://www.webservicex.net/stockquote.asmx" rel="nofollow noreferrer">http://www.webservicex.net/stockquote.asmx</a></p>
  
  <p>WSDL: <a href="http://www.webservicex.net/stockquote.asmx?WSDL" rel="nofollow noreferrer">http://www.webservicex.net/stockquote.asmx?WSDL</a></p>