title: consuming a soap webservice-getting 500
body: <p>I have a 500 error when trying to consume a soap WS .
  code below :
  main function :</p>
  <pre><code>public void Main()
      {
          var action = &quot;XXXXXX&quot;;
          string result = SendSOAPRequest(&quot;http://XXXXXXXX:80/XXXX&quot;,  action, new Dictionary&lt;string, string&gt;() , false);
      }
  </code></pre>
  <p>sendrequest method :</p>
  <pre><code>public void Main()
      {
          var action = &quot;XXXXXX&quot;;
          string result = SendSOAPRequest(&quot;http://XXXXXXXX:80/XXXX&quot;,  action, new Dictionary&lt;string, string&gt;() , false);
      }
  
      public static string SendSOAPRequest(string url, string action,Dictionary&lt;string, string&gt; parameters, bool useSOAP12 = false)
      {
          try{
          
          XmlDocument soapEnvelopeXml = new XmlDocument();
          var xmlStr = (useSOAP12)
              ? @&quot;XXXXXX&quot;;
          string parms = string.Join(string.Empty, parameters.Select(kv =&gt; String.Format(&quot;&lt;{0}&gt;{1}&lt;/{0}&gt;&quot;, kv.Key, kv.Value)).ToArray());
          var s = String.Format(xmlStr, action, new Uri(url).GetLeftPart(UriPartial.Authority) + &quot;/&quot;, parms);
          soapEnvelopeXml.LoadXml(s);
          HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url + &quot;/&quot; + action));
          webRequest.Headers.Add(&quot;SOAPAction&quot;, url);
          webRequest.Headers.Add(&quot;XXXXXX&quot;, &quot;AG6YUTGV6&quot;);
          webRequest.ContentType = (useSOAP12) ? &quot;application/soap+xml;charset=\&quot;utf-8\&quot;&quot; : &quot;text/xml;charset=\&quot;utf-8\&quot;&quot;;
          webRequest.Accept = (useSOAP12) ? &quot;application/soap+xml&quot; : &quot;text/xml&quot;;
          webRequest.Method = &quot;GET&quot;;
  
         string usernamePassword = &quot;username&quot; + &quot;:&quot; + &quot;pass&quot;;
          usernamePassword = Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)); 
          CredentialCache mycache = new CredentialCache();
          webRequest.Credentials = mycache;
          webRequest.Headers.Add(&quot;Authorization&quot;, &quot;Basic &quot; + usernamePassword);
  
          
          using (WebResponse response = webRequest.GetResponse())
          {
              using (Stream stream = response.GetResponseStream())
              {
                  XmlTextReader reader = new XmlTextReader(stream);
                 
              }
          }
          
          using (Stream stream = webRequest.GetRequestStream())
          {
              soapEnvelopeXml.Save(stream);
          }
  
          string result;
          using (WebResponse response = webRequest.GetResponse())
          {
              using (StreamReader rd = new StreamReader(response.GetResponseStream()))
              {
                  result = rd.ReadToEnd();
              }
          }
          return result;
      }
          catch (WebException ex)
          {
              string message = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
          }
          return &quot;&quot;;
      }
  </code></pre>