开发者

How to programmatically set WCF client maxBufferSize parameters?

开发者 https://www.devze.com 2023-02-05 03:36 出处:网络
I am setting wcf client parameters programmatically like below: try { ServiceReference1.MyDbServiceClient webService =

I am setting wcf client parameters programmatically like below:

try
{
ServiceReference1.MyDbServiceClient webService =
    new ServiceReference1.MyDbServiceClient(new System.ServiceModel.BasicHttpBinding(),
    new System.ServiceModel.EndpointAddress((string)((App)Application.Current).Resources["wcfMyDBServiceEndPoint"]));

    webService开发者_Python百科.GetSeriesImagesCompleted += new EventHandler<ServiceReference1.GetSeriesImagesCompletedEventArgs>(webService_GetSeriesImagesCompleted);
    webService.GetSeriesImagesAsync(index);
}

It works just fine for the default maxBufferSize. However when a client exceeds the default size, an exception is throughn: "the maximum message size quota for incoming messages (65536) has been exceeded."

How to set this parameter in code? Thanks.


BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.CloseTimeout = new TimeSpan(00, 05, 00);
binding.OpenTimeout = new TimeSpan(00, 05, 00);
binding.ReceiveTimeout = new TimeSpan(00, 05, 00);
binding.SendTimeout = new TimeSpan(00, 05, 00);
binding.TextEncoding = System.Text.Encoding.UTF8;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.MaxBufferSize = int.MaxValue;             

binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, XmlDictionaryReaderQuotas.Max, null);

Create binding based on your requirement.

0

精彩评论

暂无评论...
验证码 换一张
取 消