 |
|
|
When I am running my site with your adjustments, it does not seem to use the CompressibleHttpRequestCreator object to create the web request.
The unusual behaviour extends to the fact, if i break the code within visual studio and then use the immediate window to manually create a webrequest, then it actually does run and use the appropriate class.
Any assistance would be appreciated.
Thanks
Matt Thompson
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
As far as I know with .Net 2.0 you just have to add this line, where "request" is a HttpWebRequest object:
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
Is there any other reason I might not have seen to use your solution?
Kind regards, Björn
|
| Sign In·View Thread·PermaLink | 4.40/5 (2 votes) |
|
|
|
 |
|
|
None, other than the fact that I missed it completely. I already submeted the correction.
Thanks a lot Björn.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Thanks for the article!
But, compiling the code, I've got two warnings:
1. CompressibleHttpWebResponse.cs(20,10): warning CS0618: 'System.Net.HttpWebResponse.HttpWebResponse(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' is obsolete: 'Serialization is obsoleted for this type. http://go.microsoft.com/fwlink/?linkid=14202'
2. CompressibleHttpWebRequest.cs(27,28): warning CS0618: 'System.Net.HttpWebRequest.HttpWebRequest(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' is obsolete: 'Serialization is obsoleted for this type. http://go.microsoft.com/fwlink/?linkid=14202'
Of course, we can just ignore this, but is there a good way to fix it?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks nzeemin.
Unfortunatelly this was the only way I found to implement this.
You can add a #pragma directive to ignore this warning in this case.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I'm sorry but I'm failing to understand your point.
My article is about client-side and your links point to the server-side of the problem. They are not the same thing but one needs the other.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Greetings Paulo,
I've implemented your code and everything seems to work correctly except the ContentEncoding property from the HttpWebResponse object is returning "", not 'gzip', or 'deflate', which of course is a major problem.
This app is a Windows Forms program using Web Services and .NET 2.0. I've dropped in your code and modified the app.config in between the configuration tags as: type="Pajocomo.Net.CompressibleHttpRequestCreator, MyAssm" />
Fiddler is showing 'Accept-Encoding: gzip, deflate' so it seems the encoding request is being sent to the server but it's not responding as needed. Is there anything I need/can to do to the server to get it to compress properly
Thank you, Ed
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Ed,
The way the protocol works is by the client announcing to the server what encondings it accepts. If the server is capable of using one of them, it encondes the response and adds the respective Content-Encoding HTTP header.
IIS 6.0 is capable of handling this, but lower version aren't.
For IIS 5.x, you can add an HTTP module to your ASP.NET application to handle compression. Here is an example of one implementation: http://www.blowery.org/code/HttpCompressionModule.html.
You can, also, use Fiddler to emulate server side compression.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Hi Paulo,
Well, we've finally found the time to move this app to IIS 6.0 and that's when I found that compression still wasn't working.
I've enabled HTTP Compression in Web Site Properties from IIS Manager for IIS 6.0 and can't find any other properties to set.
This app uses XML data objects (soap) passed from a Winforms client to a webservice dll now on Server 2003. Do you know if there is anything further I can do to get it working in our environment? We appreciate your article and consideration.
Thank you, Ed
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Have you checked with Fiddler if the rigth HTTP headers are being sent?
You should be aware that this is a server side compression only protocol and, ASMX being a dynanlic content needs compression explicitly enabled on IIS6.
If you need to send compressed data to your web server, you need to code your web service to handle that (or your WCF binding).
There are also issues with this on .NET 1.1. I wonder if they affect .NET 2.0.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Of course you're right about the dynamic content in IIS 6.0. I followed the instructions here:
http://www.wwwcoder.com/main/parentid/170/site/3669/68/default.aspx
and everything is working fine. Thank you Paulo.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
can't compile the code including the given classes since I miss the System.Runtime.Serialization reference.
and it's no where to be found.
any suggestions?...
thanks
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
You can find it int he framework directory (usually, C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727).
I don't believe my code needs it, though.
Paulo Morgado Portugal - Europe's West Coast
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
well, I got to the problem: I'm developing for a device, and the Compact Framework does not contain the System.Runtime.Serialization library, so I can't use your methods. is there ant way of using another serialization method maybe to get the sae result with CF? and yet another question - does your compression work on IIS 5.1? is it IIS dependant? cause for now I'm using the IIS 6.0 compression (gzip), but I need to be able to do the same via IIS 5.1, which does not support http compression.
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Well, I've never developed for the Compact Framework, so I don't have a feeling for what's there and what's not.
This classes I've developed are not server dependent and can be used to replace HttpWebRequest and HttpWebResponse for the desired addresses just by adding some elements to the application's configuration file.
In your case, you'll need to develop a new set of classes (probably derived from WebRequest/WebResponse instead of HttpWebRequest/HttpWebResponse) and bind your applications to them. You'll find several examples of that around the internet.
The way this works is announcing to the server that the client is accepting GZIP and DEFLATE compression methods and it can send a response using that compression methods.
For IIS 5.x, you can add an HTTP module to your ASP.NET application to handle compression. Here is an example of one implementation: http://www.blowery.org/code/HttpCompressionModule.html.
Paulo Morgado Portugal - Europe's West Coast
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I implement your solution and I can not now handle web specific exception.
when I implement your solution the code crash with The remote server returned an error: (500) Internal Server Error, in method base.GetResponse() in this code in CompressibleHttpReques. can somebody help?
Petr M.
public override WebResponse GetResponse() { BeforeGetResponse(); return AfterGetResponse(base.GetResponse() as ISerializable); }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
public override WebResponse GetResponse() { try { BeforeGetResponse(); return AfterGetResponse(base.GetResponse() as ISerializable); } catch (WebException webEx) { throw new WebException(webEx.Message, webEx.InnerException, webEx.Status, AfterGetResponse(webEx.Response)); } }
...
public override WebResponse EndGetResponse(IAsyncResult asyncResult) { try { return AfterGetResponse(base.EndGetResponse(asyncResult) as ISerializable); } catch (WebException webEx) { throw new WebException(webEx.Message, webEx.InnerException, webEx.Status, AfterGetResponse(webEx.Response)); } }
Modifying the above methods in CompressibleHttpWebRequest allows for SOAP exceptions to be read correctly. This is because when an HTTP error is thrown, the WebException.Response property contains the error stream, which needs to be turned into the CompressibleHttpWebResponse stream for any compressed stream to be read. SOAP exceptions / reading HTTP error streams will now work correctly.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
I cant get it working :/
I have compiled it into a dll and put it in ~/Bin and I had set up the web.config like described above but nothing happens, all works as like as without this (checked with ethereal and fiddler)...
But the Type seems to be correctly; if i execute type.gettype with it out of my web, I get the correct type out of the .dll.
Are there some things to know, such as needed security privileges? Is it possible to add this libary from source-side (global.asax)?
Thanks for all
Sorry for my english 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Using Ethereal and Fiddler, did you check if the Accept-Encoding is being sent?
You could set breakpoints in CompressibleHttpRequestCreator.Create, CompressibleHttpWebRequest.BeforeGetResponse, CompressibleHttpWebRequest.AfterGetResponse and CompressibleHttpWebResponse.GetResponseStream to see what's going on.
To make sure the right classes are instantiated, you can, also, create the WebRequest instance like this:
IWebRequestCreate webRequestCreate = new CompressibleHttpRequestCreator(); WebRequest webRequest = webRequestCreate.Create(uri); WebResponse webResponse = webRequest.GetResponse();
You can register a IWebRequestCreate descendant for a spceified prefix in code using WebRequest.RegisterPrefix, but you can't override the definitions for HTTP and HTTPS. And you would end up with your code tightly coupled with these classes. This is the sort of thing you want plugguble.
Paulo Morgado Portugal - Europe's West Coast
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Well thats my problem. The headers are sent successfully and they arrive in asp.net, too. If I debug this dll and set breakpoints, they never reached.
It seems asp.net ignores the settings in web.config, because i can type in every class- and assemblynames, even they exists or not, it wont throw an error (like 'assembly not found')
I have tried to put in the sources (converted to vb) in my web project, too but with the same reason. No error, no compression and without reaching breakpoints... 
I tried on IIS5.1 (XP Pro) and IIS6 (WinSrv2003), its all the same :/
Sorry for my englich 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
If you added the code to your sources (no need to convert to vb with 2.0) you can step into the code with this:
IWebRequestCreate webRequestCreate = new CompressibleHttpRequestCreator(); WebRequest webRequest = webRequestCreate.Create(uri); WebResponse webResponse = webRequest.GetResponse();
Fiddler, in the Rules menu has a Simulate GZIP Compression. Have you tried it.
If the Accept-Encoding header are being sent, it's because CompressibleHttpWebRequest.BeforeGetResponse is being executed.
Paulo Morgado Portugal - Europe's West Coast
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Converting: I dont now that before, thanks for that  And yes, I tried the gzip simulating in Fiddler and it works fine.
Something happens: If I try your code below or the handler, you provided earlier to someone else, asp.net throws me an error 'Could not find assembly'. I corrected it and now it seems to work for outgiong requests. (runs on timeout or http500 on serverside mostly, i try more with it )
Does this code only work for outgoing http-requests? 0.o I have thought, everyone (that can extract it) receive my web compressed ?
But many thanks for your support yet
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |