Change max message size in DataServiceContext
I am using DataServiceContext
to get data from a wcf service which is hosting a dbml. It works fine in general but queries that return large amounts of data (e.g. binary files) create the usual WCF error:
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding
The problem is I cannot find how to change the message size of the channel.
Here's the code I use to initialise the class:
var channel = new RPDataModelDataContext(DataServiceBaseAddress);
channel.Credentials = Creden开发者_运维百科tialCache.DefaultCredentials;
where RPDataModelDataContext
is a client proxy class generated with the entityframework
public partial class RPDataModelDataContext :
global::System.Data.Services.Client.DataServiceContext
{
// ...
Can anyone point me to the right direction?
I was having tons of problems with this one as well. There were three details I was missing.
- You MUST specify the service
name
exactly. This should be the fully qualified service name. (ie. Namespace.ClassName) You MUST provide the EXACT
address
of the endpoint. (See code below)<services> <!-- The service name below has to be the EXACT Namespace.ClassName of your WCF Data Service--> <service name="YourDomainNameHere.YourClassNameHere"> <!-- The address below must be the EXACT address of your service--> <endpoint address ="http://localhost:19766/YourServiceName.svc" binding="webHttpBinding" bindingConfiguration="higherMessageSize" contract ="System.Data.Services.IRequestHandler"> </endpoint> </service> </services>
The
maxReceivedMessageSize
and themaxBufferSize
must both be specified<bindings> <webHttpBinding> <!-- The maxReceivedMessageSize and the maxBufferSize must both be specified as shown below--> <binding name="higherMessageSize" maxReceivedMessageSize ="2048000" maxBufferSize="2048000"/> </webHttpBinding> </bindings>
EDIT: This may actually be a service-side issue. You should ensure that service configuration file is set as shown at the answer with most votes. You basically need to change the MaxReceivedMessageSize value to something a little bigger than your largest expected query results size. I've had to set it as high as 2 MB without any issues.
After some research I found no way to customise the Data channel service client. So I guess that its not possible to.
One has to create a normal wcf client to interact with it.
精彩评论