简体   繁体   中英

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"

WCF Data Services isn't very good at writing large amounts of data.

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.

You can try by increasing MaxStringContentLength and MaxReceivedMessageSize values.

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

<dataContractSerializer maxObjectsInGraph="1000000000"/> 

Also would be easy if you can post your service configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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