title: Soap call gives 500 (internal server error) in c#
body: <p>I have one affiliate account and I need to make a <code>soap</code> call to get data. I got ready code from one site and I tried to apply it, but I'm getting <code>500(internal server error)</code>. My code is given below.</p>
  
  <pre><code>public void getdata()
  {
      var _url = "http://secure.directtrack.com/api/soap_affiliate.php";
      var _action = "http://secure.directtrack.com/api/soap_affiliate.php/dailyStatsInfo";
  
      XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
      HttpWebRequest webRequest = CreateWebRequest(_url, _action);
      InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
  
      // begin async call to web request.
      IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
  
      // suspend this thread until call is complete. You might want to
      // do something usefull here like update your UI.
      asyncResult.AsyncWaitHandle.WaitOne();
  
      // get the response from the completed web request.
      string soapResult;
      using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
      using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
      {
          soapResult = rd.ReadToEnd();
      }
      Console.Write(soapResult);
  
  }
  
  private static HttpWebRequest CreateWebRequest(string url, string action)
  {
      HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
      webRequest.Headers.Add("SOAPAction", action);
      webRequest.ContentType = "text/xml;charset=\"utf-8\"";
      webRequest.Accept = "text/xml";
      webRequest.Method = "POST";
      return webRequest;
  }
  
  private static XmlDocument CreateSoapEnvelope()
  {
      XmlDocument soapEnvelop = new XmlDocument();
  
      soapEnvelop.LoadXml(@"&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema""&gt;&lt;SOAP-ENV:Body  xmlns=""http://soapinterop.org//"" SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""&gt; &lt;q1:Execute xmlns:q1=""http://secure.directtrack.com/api/soap_affiliate.php/dailyStatsInfo""&gt;&lt;client xsi:type=""xsd:string""&gt;MyClientNAme&lt;/client&gt;&lt;add_code xsi:type=""xsd:string""&gt;MyCode&lt;/add_code&gt;&lt;password xsi:type=""xsd:string""&gt;MyPassword&lt;/password&gt;&lt;program_id xsi:type=""xsd:int""&gt;161&lt;/program_id&gt;&lt;/q1:Execute&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;");
  
  
      return soapEnvelop;
  }
  
  private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
  {
      using (Stream stream = webRequest.GetRequestStream())
      {
          soapEnvelopeXml.Save(stream);
      }
  }
  </code></pre>
  
  <p>What is the problem? Thanks in advance.</p>