传输 byte[] 时 WCF 数据服务中出现异常
我正在测试我最近设置的 WCF 数据服务。
大多数事情都运行良好,只有一个集合,当我添加一个对象并保存更改时,我得到了这个异常:
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:
它是唯一包含文件( byte[] )的对象,所以我认为问题是因为这个文件(大小?...?)即使我激活了详细错误,错误也不会告诉我很多信息:
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
我对此集合拥有所有权利:
config.SetEntitySetAccessRule("OrderFile", EntitySetRights.All);
这是我添加文件的方式:
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
}
我尝试添加
<httpRuntime maxRequestLength="2097152"/>
到我的元素
如果我发送一个空的txt文件,它作品。
有什么想法吗?
谢谢你!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里找到解决方案: http://malvinly.com/2011 /05/09/wcf-data-services-and-maxreceivedmessagesize/
Found the solution here: http://malvinly.com/2011/05/09/wcf-data-services-and-maxreceivedmessagesize/