Question MaxReceivedMessageSize property : How to change it ?

Origami

Member
Joined
Jan 12, 2011
Messages
8
Programming Experience
5-10
Hi all,

Now that I can call the WebServices, I have a problem with one of them with returns a hudge amount of data (which is what it's supposed to do).

The error is :
System.ServiceModel.CommunicationException was unhandled by user code
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.

What is the "appropriate binding element" ? I'm using a Service reference that connects to a WebService through a WSDL file.

Note : I found on Internet some clue, saying that I should use the System.ServiceModel.WSHttpBinding.
The current code is this :
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim Binding As System.ServiceModel.WSHttpBinding = New System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None)
Binding.MaxReceivedMessageSize = 50000000

Dim AAA_SC As New SR_toto.AaaExportServiceClient
Dim ID_Requis(0) As Long
ID_Requis(0) = 54

Dim cc() As SR_toto.appelSummaryWS
cc = AAA_SC.getAppels(ID_Requis)

It still fails, saying that there is too much data. How can I tell the WebService call to use the Binding object ?

Thanks a lot for your help.
 
Last edited:
When you added the service reference configuration for system.serviceModel was added to the project app.config file, here you can see client/endPoint that refers to a bindingConfiguration, which exist in the bindings collection in same file. In that file you can set default values for the binding. In code these properties can be set dynamically using the client object and its EndPoint.Binding property, though you have to cast to correct type for example BasicHttpBinding type. You may have to set maxBufferSize to same value also.
 
You're the Best ! It was indeen in the app.config file.
I had to change both values MaxReceivedMessageSize and MaxBufferSize as they must be of the same value.
Put them to 20,000,000. Should be OK.

Thank you very much !
 
I had to change both values MaxReceivedMessageSize and MaxBufferSize as they must be of the same value.
For buffered bindings (TransferMode) it appears they must be the same, and that is the default transfer mode. Documentation says they are the same for that mode, but that didn't happen last I checked.
 
Back
Top