title: IIS 7.5 Restful service returns Error 411 - length required from .net client but not fiddler
body: <p>I'm using a Microsoft Stack: Windows Server 2008 R2 / IIS 7.5; .NET 4.0 </p>
  
  <p>Setting up the service on localhost, the client call the operation without a hitch. Setting up the service (originally as a Post then as a Get) I get the following error from .NET (method below). If I make the call directly through fiddler everything works and the (RAW) header is as follows:</p>
  
  <p>HTTP/1.1 200 OK
  Cache-Control: private
  Content-Length: 19854411
  Content-Type: application/xml; charset=utf-8
  Server: Microsoft-IIS/7.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET</p>
  
  <p>If I make a call through console app or windows service I get the following error
  "The remote server returned an error: &lt;411> Length Required."</p>
  
  <p>I have a web service that is supposed to return a zip file after doing some work</p>
  
  <pre><code>    [OperationContract]
      [WebInvoke(UriTemplate = "/GetFiles/{profileLocationId}/{batchSize}", Method = "GET", RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
      public byte[] ProfileImagesByProfileId(string profileLocationId, string batchSize)
      {
          //  var watch = new Stopwatch();
          //  watch.Start();
          try
          {
              long id = 0;
              long.TryParse(profileLocationId, out id);
  
              int size = 200;
              int.TryParse(batchSize, out size);
  
              var profileRoot = ConfigurationManager.AppSettings["ProfileImageRootDirectory"];
              var fileType = ConfigurationManager.AppSettings["ProfileImageDefaultFileType"];
  
  
              var packer = new ImagePackager(profileRoot, fileType);
              if (profileLocationId != null)
              {
                  var stream = packer.CompressImages(id, size);
  
                  return stream;
              }
          }
          catch (Exception ex)
          {
              return new byte[0];
  
          }
  
          return new byte[0];
      }
  }
  </code></pre>
  
  <p>===========================</p>
  
  <h1>client method</h1>
  
  <pre><code> static void TimerElapsed(object sender, ElapsedEventArgs e)
      {
          var id = GetLastProfileId();
  
         // var uri = string.Format("http://{0}/TwitterService/ProfileImages/{1}/{2}", _ipAddress, id, _batchsize);
          var uri = string.Format("http://{0}/Twitter_api/TwitterService/ProfileImages/{1}/{2}", _ipAddress, id, _batchsize);
          GetProfileImagesFromService(uri);
      }
  
  
      private static void GetProfileImagesFromService(string uri)
      {
          try
          {
              Console.WriteLine("Process started: {0}", DateTime.Now.ToLongTimeString());
              var request = WebRequest.Create(uri);
              request.Method = "GET";
              request.Timeout = 600000;
              using (var response = (HttpWebResponse)request.GetResponse())
              {
                  Console.WriteLine(response.StatusDescription);
                  var dataStream = response.GetResponseStream();
                  var reader = new StreamReader(dataStream, Encoding.UTF8);
                  //  var responseFromServer = reader.ReadToEnd();
  
                  var fileName = string.Format(@"{0}\{1:yyMMddhhmmss}.zip", _targetDirectory, DateTime.UtcNow);
                  // File.WriteAllText(fileName, responseFromServer);
                  // var xml = XDocument.Parse(responseFromServer);
                  var xml = XDocument.Load(reader);
                  var base64 = xml.Root.Value.ToCharArray();
  
                  var byteArray = Convert.FromBase64CharArray(base64, 0, base64.Length);
  
                  File.WriteAllBytes(fileName, byteArray);
                  Console.WriteLine("GetProfile cycle ended: {0}", DateTime.Now.ToLongTimeString());
              }
          }
          catch (Exception ex)
          {
  
              Console.WriteLine(ex.Message);
          }
      }
  </code></pre>
  
  <hr>
  
  <p>Any guidance would be extremely appreciated. </p>
  
  <p>Thank you in advance.</p>