I'm testing a recent WCF Data Service that I've set.
Most of things are working good, there is only one collection, when I add an object and save change, I got this exception:
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.<HandleBatchResponse>d__1e.MoveNext()
InnerException:
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:
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
I've all rights on this collection:
config.SetEntitySetAccessRule("OrderFile", EntitySetRights.All);
Here is how I add my file:
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
}
I tried to add
<httpRuntime maxRequestLength="2097152"/>
To my element
If I send an empty txt file, it works.
Any idea?
Thank you!
Found the solution here: http://malvinly.com/2011/05/09/wcf-data-services-and-maxreceivedmessagesize/