title: Exception in a WCF Data service when transfering a byte[]
body: <p>I'm testing a recent WCF Data Service that I've set.</p>
  
  <p>Most of things are working good, there is only one collection, when I add an object and save change, I got this exception:</p>
  
  <pre><code>  System.Data.Services.Client.DataServiceRequestException was unhandled
    Message=Une erreur s'est produite lors du traitement de cette requête.
    Source=System.Data.Services.Client
    StackTrace:
         à System.Data.Services.Client.DataServiceContext.SaveResult.HandleBatchResponse()
         à System.Data.Services.Client.DataServiceContext.SaveResult.EndRequest()
         à System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
         à System.Data.Services.Client.DataServiceContext.SaveChanges()
         à WSTester.Program.AddSomeThings(Entities entities) dans D:\MyPath\MAIN\WSTester\Program.cs:ligne 153
         à WSTester.Program.Main(String[] args) dans D:\MyPath\MAIN\WSTester\Program.cs:ligne 26
         à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
         à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
         à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         à System.Threading.ThreadHelper.ThreadStart()
    InnerException: System.Data.Services.Client.DataServiceClientException
         Message=BadRequest
         Source=System.Data.Services.Client
         StatusCode=400
         StackTrace:
              à System.Data.Services.Client.DataServiceContext.SaveResult.&lt;HandleBatchResponse&gt;d__1e.MoveNext()
         InnerException: 
  </code></pre>
  
  <p>It's the only object which contains a file( byte[] ), so I think that the problem is because of this file(size? ...?) the error doesn't tell me a lot even if I've activate the verbose faults:</p>
  
  <pre><code>[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
  </code></pre>
  
  <p>I've all rights on this collection: </p>
  
  <pre><code>    config.SetEntitySetAccessRule("OrderFile", EntitySetRights.All);
  </code></pre>
  
  <p>Here is how I add my file:</p>
  
  <pre><code>OrderFile orderFile = new OrderFile() { BinaryFile = StreamFile("BC0201001.pdf"), DateAdded = DateTime.Now, FileName = "BC0201001.pdf", IDOrder = order.IDOrder};
  entities.AddToOrderFile(orderFile);
  entities.SaveChanges();
  
  //and this the method which put a file into a byte[]
          private static byte[] StreamFile(string filename)
          {
              FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
  
              // Create a byte array of file stream length
              byte[] ImageData = new byte[fs.Length];
  
              //Read block of bytes from stream into the byte array
              fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
  
              //Close the File Stream
              fs.Close();
              return ImageData; //return the byte data
          }
  </code></pre>
  
  <p>I tried to add </p>
  
  <pre><code>&lt;httpRuntime maxRequestLength="2097152"/&gt;
  </code></pre>
  
  <p>To my  element</p>
  
  <p>If I send an empty txt file, it works.</p>
  
  <p>Any idea?</p>
  
  <p>Thank you!</p>