Recently I was developing a SharePoint timer Job that references a WCF Service to retrieve some information. I was getting the following message –
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
The increase the MaxReceivedMessageSize you normally change the configuration file as follows –
<binding name=”BasicHttpBinding_MyService” maxBufferSize=”2147483647″ maxReceivedMessageSize=”2147483647″ />
But I was writing SharePoint timer Job and the timer job normally uses the owstimer.exe.config file. The file is located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
I was not in favor of changing the config file so I wrote the following code to set the maxReceivedMessageSize –
BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
EndpointAddress remoteAddress = new EndpointAddress(“<your service URL>”);
MyService.ServiceClient service = new MyService.ServiceClient(binding, remoteAddress);
MyService.fieldResponse fieldResponse = service.<Method>;
Happy coding….