title: Posting XML data to a Web Service via Console App
body: <p>I have a web service in my QA box that accepts and process an XML string, send an email and then returns another XML string. To test it, I want to overload it by making a console app to call it by sending it an XML, making make a loop in the console app so it sends it 1,000 times in one shoot. I seen a lot of sample in the internet but I can't get them to work.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Net;
  using System.Text;
  using System.Threading.Tasks;
  using System.Xml;
  using System.Xml.Linq;
  
  namespace WSStressTest
  {
      class Program
      {
          static void Main()
          {
              ASCIIEncoding encoding = new ASCIIEncoding();
              string postData = "&lt;?xml version='1.0'?&gt;&lt;ROOT&gt;&lt;SOMETHING&gt;&lt;/SOMETHING&gt;&lt;/ROOT&gt;";
  
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://url:1111/WebService.asmx/ProcessWebService");
              request.Method = "POST";
              byte[] data = encoding.GetBytes(postData);
              request.ContentType = "application/x-www-form-urlencoded";
              request.ContentLength = data.Length;
              Stream dataStream = request.GetRequestStream();
              dataStream.Write(data, 0, data.Length);
              dataStream.Close();
  
              HttpWebResponse response = (HttpWebResponse)request.GetResponse();
              Console.WriteLine(((HttpWebResponse)response).StatusDescription);
              dataStream = response.GetResponseStream();
              StreamReader reader = new StreamReader(dataStream);
              string responseFromServer = reader.ReadToEnd();
              Console.WriteLine(responseFromServer);
  
              reader.Close();
              dataStream.Close();
              response.Close();
              //Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>I always get an 500 error in HttpWebResponse. Now, looking at the code the only thing I can think that is missing is the name of the parameter for POST. What I mean, if I make a form</p>
  
  <pre><code>&lt;form method="post" action="http://url:1111/WebService.asmx/ProcessWebService"&gt;
      &lt;input type="text" name="sXML" /&gt; &lt;input type="submit" value="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>placing the xml in the input and submit will work. But I'm naming the data post to the web service <strong>sXML</strong>. How do I name the xml post in the console app sXML? Is that what I'm missing or is there another error in my code?</p>
  
  <p><em>Additional question: What would be the best way to get this to run 1,000 times. I was thinking of putting the call inside a while &lt;1000. Is there a better way for it?</em></p>
  
  <p>Thanks!</p>