Attilah
Attilah

Reputation: 17930

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"

Upvotes: 1

Views: 830

Answers (4)

Roy Dictus
Roy Dictus

Reputation: 33139

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.

Upvotes: 2

Rajesh
Rajesh

Reputation: 7876

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.

Upvotes: 0

UnhandledExcepSean
UnhandledExcepSean

Reputation: 12804

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

Upvotes: 1

Damith
Damith

Reputation: 63065

You can try by increasing MaxStringContentLength and MaxReceivedMessageSize values.

This blog will help you.

Upvotes: 1

Related Questions