2011-01-18 5 views
3

私はプログラム的に以下のようなWCFクライアントのパラメータを設定しています:WCFクライアントのmaxBufferSizeパラメータをプログラムで設定する方法は?

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

    webService.GetSeriesImagesCompleted += new EventHandler<ServiceReference1.GetSeriesImagesCompletedEventArgs>(webService_GetSeriesImagesCompleted); 
    webService.GetSeriesImagesAsync(index); 
} 

それはデフォルトのMaxBufferSizeのためだけで正常に動作します。ただし、クライアントがデフォルトサイズを超えると、「受信メッセージ(65536)の最大メッセージサイズクォータが超過しました」という例外がありません。

コードでこのパラメータを設定するにはどうすればよいですか?おかげさまで

答えて

10
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); 

要件に基づいてバインディングを作成します。

+0

ありがとうございました。同様に、私の問題は、MaxReceivedMessageSizeと同じMaxBufferSizeを持たなければならないということでした。 – val

+0

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d2090703-eb60-46f4-adf7-31127338a0a0/これが役立つことを願っています – hungryMind

+1

WCFは私たちを守るのが難しいです。これは良い答えです:) – dana