Last post Apr 13, 2012 04:11 PM by DickP
Apr 13, 2012 12:24 PM|DickP|LINK
I am trying to set up an MVC4 reverse proxy for my MVC4 backend. The RP only contains delegating handlers to transparently forward requests using httpclient. The connection to the backend uses windows authentication with the default service credentials.
It was a hassle but it appears to now work with both sites on my dev machine although I have lingering doubts. It does not work when Fiddler is running and my earlier prototype RP no longer works at all although it is substantially the same.
but there is something wrong with HttpClient.
When I try to request the js file I get the familiar HttpRequestException: Cannot write more bytes to the buffer than the configured maximum buffer size: 65536.
When I set MaxResponseContentBufferSize to any value I get MissingMethodException. Method not found: 'Void System.Net.Http.HttpClient.set_MaxResponseContentBufferSize(Int64)'. Yet the method is certainly there in reflector.
When I request the same jquery js file from jquery.com it loads no problem. Maybe the windows authentication is the problem?
When I request a big pdf file it loads no problem.
I am using the latest nuget beta drops of MVC4 and System.Net.Http on .net 4.0 Windows7 x64. Maybe I'm picking up an earlier version of httpclient but I can't see it.
Any assistance appreciated. Here's my console app code:
WebRequestHandler handler = new WebRequestHandler();
string big = "http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf";
string s = "http://myhost:10080/Scripts/jquery-1.7.1.min.js";
string url = s;
handler.UseDefaultCredentials = true;
HttpClient client = new HttpClient(handler);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
var r = client.SendAsync(request).Result;
Apr 13, 2012 01:08 PM|Darrel Miller|LINK
You must have an old copy of HTTPClient stuffed in there somewhere. I just tried your code with a similar JS file and it worked fine. The max buffer on my HttpClient is set at 2GB.
Another thing you may want to look at if you are building a reverse proxy is the HttpCompletionOption paramter on SendAsync. This will allow you to get the control back from the origin server as soon as the headers have arrived. Then you can copy the response
stream from the origin server directly into the response stream going to the client. This will avoid buffering all the content on the reverse proxy.
Apr 13, 2012 01:46 PM|rossco|LINK
Do you have .net 4.5 beta or Visual Studio 11 installed? I had the same thing and the only way to solve it was to uninstall VS 11 beta, then repair my VS2010 and .net 4 installs.
It looks like there is a conflict with that method and .net 4.5.
Apr 13, 2012 01:47 PM|DickP|LINK
I now know it should work and the problem is local to my environment. I previously downloaded Preview 6 and others before but I can't remember which. The old stuff must still be in the GAC, otherwise I can't see how a new project would reference it. I'll
Apr 13, 2012 01:50 PM|DickP|LINK
I do have 4.5 installed though not VS11. Installation of MVC4 was extremely traumatic. I'll remove 4.5 and see what happens.
Apr 13, 2012 04:09 PM|DickP|LINK
Uninstalling framework 4.5 fixed it. VS would not work afterwards. I had to reinstall framework 4.0 and all the updates. ZZZZzzzzzz
Somehow 4.5 installed itself as part of the MVC4 install. The install failed repeatedly and I ended up installing 4.5 manually because I assumed it was required.
Apr 13, 2012 04:11 PM|DickP|LINK
Thanks for the heads up on the HttpCompletionOption. I missed that one.