I want to set the MaxReceivedMessageSize property to some higher limit (Due to (400) Bad Request error) in my client programmatically. This is the code I am using...
WCFServiceTestClient wcfClient =
new WCFServiceTestClient(new wsHttpBinding(), strServiceURL);
My service url is dynamic and hence cannot use the web.config.
//The following code doesn't seem to take effect
((WSHttpBinding)wcfClient.ChannelFactory.Endpoint.Binding)
.MaxReceivedMessageSize = 2147483647;
What am I doing wrong?
You need to set the MaxReceivedMessageSize attribute in your binding configuration. By default, it is 65536.
MaxReceivedMessageSize = 1000000; The value of this property can also be set in the configuration file.
Have you tried re-ordering the calls so that you set the MaxReceivedMessageSize before instantiating the client? eg,
var binding = new wsHttpBinding();
binding.MaxReceivedMessageSize = Int32.MaxValue;
var wcfClient = new WCFServiceTestClient(binding, strServiceURL);
This may or may not help your 400 error, though.
I had similar problems in my wcf-service and I solved it with:
CustomBinding binding = (CustomBinding)PDAServiceContractClient.CreateDefaultBinding();
HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement();
httpBindingElement.MaxBufferSize = Int32.MaxValue;
httpBindingElement.MaxReceivedMessageSize = Int32.MaxValue;
binding.Elements.Add(httpBindingElement);
string address = PDAServiceContractClient.EndpointAddress.Uri.ToString();
m_proxy = new PDAServiceContractClient(binding, new EndpointAddress(address));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With