简体   繁体   English

WCF数据服务:400保存大量更改时的错误请求

[英]WCF Data Services : 400 Bad Request when saving lots of changes

I have a client that creates thousands of entities and sends it over to the service like so : 我有一个客户端创建数千个实体并将其发送到服务,如下所示:

for(int i=0;i<99999999; i++)
{
    var contract = new Contract { Id = i, Name = "Ctr" + i.ToString() , ... }
    service.AddToContracts(contract);
}

svc.SaveChanges(SaveChangesOptions.Batch);

the problem is that when I try to save the changes, I get the following exception : 问题是当我尝试保存更改时,我得到以下异常:

"400 - Bad Request" “400 - 错误请求”

WCF Data Services isn't very good at writing large amounts of data. WCF数据服务不是很擅长编写大量数据。

I got into trouble about a year ago when my code tried to write 100,000 objects... I modified the code to add the objects in smaller chunks (losing the transactional nature of my operation), which worked. 大约一年前,当我的代码试图编写100,000个对象时,我遇到了麻烦......我修改了代码,将对象添加到较小的块中(失去了我操作的事务性质),这很有效。

You can try by increasing MaxStringContentLength and MaxReceivedMessageSize values. 您可以尝试增加MaxStringContentLengthMaxReceivedMessageSize值。

This blog will help you. 这个博客将帮助您。

不要只在最后保存为批次,而是保存每100个合同或其他东西。

You can enable tracing on your service to get the exact error on where your request is failing and what is the cause for it? 您可以在服务上启用跟踪,以确定您的请求失败的确切错误及其原因是什么? If there are many number of entities being passed to your WCF Service try to increase the following settings in your web.config 如果有许多实体传递给您的WCF服务,请尝试在web.config中增加以下设置

<dataContractSerializer maxObjectsInGraph="1000000000"/> 

Also would be easy if you can post your service configuration. 如果您可以发布您的服务配置也很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM