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

回眸只為那壹抹淺笑 提交于 2019-12-24 08:48:05

问题


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"


回答1:


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.




回答2:


You can try by increasing MaxStringContentLength and MaxReceivedMessageSize values.

This blog will help you.




回答3:


Don't save as a batch only at the end and instead save every 100 contracts added or something.




回答4:


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.



来源:https://stackoverflow.com/questions/8304638/wcf-data-services-400-bad-request-when-saving-lots-of-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!