WCF Preview 4 client getting maximum buffer size: 65536.

Topics: Web Api
Sep 22, 2011 at 2:44 AM

I've read other discussions but for some reason I can't get this to work.

I am trying to retrieve a list of classes with the following basic code but I only get "Cannot write more bytes to the buffer than the configured maximum buffer size: 65536."

    

  HttpClient client = new HttpClient(new Uri(uri));
            client.DefaultRequestHeaders.Add("Accept","application/json");
            HttpClientChannel channel = new HttpClientChannel() { MaxRequestContentBufferSize = 1024 * 1024 * 10 };
            client.Channel = channel;
            var response = client.Get(uri);

              if (response.IsSuccessStatusCode)
                this.Result.Text = "<B>Location Response Body</B><br>" + Server.HtmlEncode(response.Content.ReadAsString());
            else
                this.Result.Text = "Status:" + response.StatusCode + " Reason:" + response.ReasonPhrase;

 

Please advise.

Sep 22, 2011 at 3:38 AM

There are two buffer sizes – one for requests and one for responses. You have set the request buffer size but likely you are hitting the response buffer size. You can set the response buffer size doing this:

HttpClient client = new HttpClient { MaxResponseContentBufferSize = 1024 * 1024 };

Of course, if you get the request content stream and write directly to it or the response content stream and read directly from it then you don’t have to buffer anything.

Henrik

From: fernandomg [email removed]
Sent: Wednesday, September 21, 2011 6:45 PM
To: Henrik Frystyk Nielsen
Subject: WCF Preview 4 client getting maximum buffer size: 65536. [wcf:273407]

From: fernandomg

I've read other discussions but for some reason I can't get this to work.

I am trying to retrieve a list of classes with the following basic code but I only get "Cannot write more bytes to the buffer than the configured maximum buffer size: 65536."

  HttpClient client = new HttpClient(new Uri(uri));
            client.DefaultRequestHeaders.Add("Accept","application/json");
            HttpClientChannel channel = new HttpClientChannel() { MaxRequestContentBufferSize = 1024 * 1024 * 10 };
            client.Channel = channel;
            var response = client.Get(uri);
 
              if (response.IsSuccessStatusCode)
                this.Result.Text = "Location Response Body
"
+ Server.HtmlEncode(response.Content.ReadAsString());
            else
                this.Result.Text = "Status:" + response.StatusCode + " Reason:" + response.ReasonPhrase;

Please advise.

Sep 22, 2011 at 10:26 PM

Thanks, it worked!

Sep 26, 2011 at 7:18 AM

What references are needed for HttpClientCHannel?

I am getting "The type or namespace name 'HttpClientChannel' could not be found (are you missing a using directive or an assembly reference?)"

 

Thanks,

Mahesh.

 
Sep 26, 2011 at 3:17 PM

It’s part of preview 5 – I don’t have preview 4 in front of me but if I remember correctly then it is not part of that.

Henrik

Coordinator
Sep 26, 2011 at 4:12 PM
Channels have been renamed to Handlers in Preview 5, HttpClientChannel is now HttpClientHandler.

Sent from my Windows Phone

From: maheshkshirsagar
Sent: 9/25/2011 11:19 PM
To: Glenn Block
Subject: Re: WCF Preview 4 client getting maximum buffer size: 65536. [wcf:273407]

From: maheshkshirsagar

What references are needed for HttpClientCHannel?

I am getting "The type or namespace name 'HttpClientChannel' could not be found (are you missing a using directive or an assembly reference?)"

Thanks,

Mahesh.