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.Channel开发者_运维百科Factory.Endpoint.Binding)
.MaxReceivedMessageSize = 2147483647;
What am I doing wrong?
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));
This works well, though it's not that obvious. It retains all the existing binding properties and only adjusts the MaxReceivedMessageSize
(which, incidentally, also increases MaxBufferSize
to the same size).
Dim oClient as WcfClient = New WcfClient
CType(oClient.Endpoint.Binding, ServiceModel.BasicHttpBinding).MaxReceivedMessageSize = Int32.MaxValue
精彩评论