title: asp.net InvalidOperationException when i use HttpWebRequest
body: <p>Here is my code:</p>
  
  <pre><code>    public Form1()
      {
          InitializeComponent();
      }
  
      // create new http request
      public void createRequest(String url, int idleTime){
          webRequest = (HttpWebRequest)WebRequest.Create(url);
          webRequest.Method = "POST";
          webRequest.KeepAlive = true;
          webRequest.UnsafeAuthenticatedConnectionSharing = true;
          ServicePointManager.MaxServicePointIdleTime = idleTime;
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          createRequest("http://freemusic.somee.com/Service.asmx/add", 100000);
      }
  
      private void txtOK_Click(object sender, EventArgs e)
      {
          if (webRequest == null)
          {
              sumTxt.Text = "HTTP cannot keep alive!";
              createRequest("http://freemusic.somee.com/Service.asmx/add", 100000);
          }
          // client send a request
          webRequest.ContentType = "application/x-www-form-urlencoded";
          String strParameter = "a=" + aTxt.Text + "&amp;b=" + bTxt.Text;
          byte[] byteArray = Encoding.UTF8.GetBytes(strParameter);
          webRequest.ContentLength = byteArray.Length;
          Stream dataStreamWriter = webRequest.GetRequestStream();
          dataStreamWriter.Write(byteArray, 0, byteArray.Length);
          //dataStreamWriter.Close();
  
          // receive response from server
          try
          {
              webResponse = (HttpWebResponse)webRequest.GetResponse();
              Stream dataStreamReader = webResponse.GetResponseStream();
              StreamReader sr = new StreamReader(dataStreamReader, Encoding.UTF8);
              String strResponse = sr.ReadToEnd();
              sumTxt.Text = strResponse;
              //webResponse.Close();
              //dataStreamReader.Close();
              //sr.Close();
          }
          catch (WebException ex)
          {
              String response = ex.Message;
              sumTxt.Text = response;
          }
      }
  </code></pre>
  
  <p>I want to create a http keep-alive connection. 'add' method in web service will receive sum of 2 input parameters a &amp; b. It ran exactly at first, but later program threw InvalidOperationException in line : webRequest.ContentLength = byteArray.Length; . How should i do in this case? </p>