title: No connection could be made because the target machine actively refused it 127.0.0.1:3446
body: <p>I'm using the WCF4.0 template -<a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" rel="noreferrer">REST</a>. I'm trying to make a method that uploads a file using a stream.</p>
  
  <p>The problem always occur at</p>
  
  <pre><code>Stream serverStream = request.GetRequestStream();
  </code></pre>
  
  <p>Class for streaming:</p>
  
  <pre><code>namespace LogicClass
  {
      public class StreamClass : IStreamClass
      {
          public bool UploadFile(string filename, Stream fileStream)
          {
              try
              {
                  FileStream fileToupload = new FileStream(filename, FileMode.Create);
                  byte[] bytearray = new byte[10000];
                  int bytesRead, totalBytesRead = 0;
                  do
                  {
                      bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);
                      totalBytesRead += bytesRead;
                  } while (bytesRead &gt; 0);
  
                  fileToupload.Write(bytearray, 0, bytearray.Length);
                  fileToupload.Close();
                  fileToupload.Dispose();
              }
              catch (Exception ex) { throw new Exception(ex.Message); }
              return true;
          }
      }
  }
  </code></pre>
  
  <p>REST project:</p>
  
  <pre><code>[WebInvoke(UriTemplate = "AddStream/{filename}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
  public bool AddStream(string filename, System.IO.Stream fileStream)
  {
      LogicClass.FileComponent rest = new LogicClass.FileComponent();
      return rest.AddStream(filename, fileStream);
  }
  </code></pre>
  
  <p>Windows Form project: for testing</p>
  
  <pre><code>private void button24_Click(object sender, EventArgs e)
  {
      byte[] fileStream;
      using (FileStream fs = new FileStream("E:\\stream.txt", FileMode.Open, FileAccess.Read, FileShare.Read))
      {
          fileStream = new byte[fs.Length];
          fs.Read(fileStream, 0, (int)fs.Length);
          fs.Close();
          fs.Dispose();
      }
  
      string baseAddress = "http://localhost:3446/File/AddStream/stream.txt";
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(baseAddress);
      request.Method = "POST";
      request.ContentType = "text/plain";
      Stream serverStream = request.GetRequestStream();
      serverStream.Write(fileStream, 0, fileStream.Length);
      serverStream.Close();
      using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
      {
          int statusCode = (int)response.StatusCode;
          StreamReader reader = new StreamReader(response.GetResponseStream());
      }
  }
  </code></pre>
  
  <p>I've turned off the firewall and my Internet connection, but the error still exists. Is there a better way of testing the uploading method?</p>
  
  <p>Stack trace:</p>
  
  <blockquote>
    <p>at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
           at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception&amp; exception)</p>
  </blockquote>