views:

717

answers:

2

I have an ADO.NET data service exposed by a .NET app (not IIS) which is consumed by a .NET client app. Some calls to this data service return large amounts of data.

I'd like to compress the XML data on the wire to reduce payload and improve performance. Is this possible?

+1  A: 

You can use GZipStream to compress and decompress it.

EKS
Can you give an example?
Ian Gregory
If you click the link. You see examples on how to compress a byte array
EKS
Yes, but how do I compress the messages passed via ADO.NET data services?
Ian Gregory
I think you'll have to get ahold of the raw XML data that the ADO.Net data services class sends out, I'm sure there is a way to intercept this. But what you do is get the XML data, turn it to an array of bytes and then compress it and send it over the wire.. the receiver must also be aware of this and such however and intercept the receiving of the XML data.
Earlz
+5  A: 

I assume you're hosting using WCF in your .NET "app"? If so, you would need write some custom MessageEncoder implementation because WCF does not provide this out of the box. Luckily there is a sample in the SDK that you can use.

I actually just realized that this is only step one of two depending on whether or not your client is also WCF? While this will encode the message, it would require that your client be using a similarly configured decoder because that implementation will not set the HTTP headers that are necessary to signal that encoding has occurred to a "pure" HTTP client. So, if it's not a WCF client on the other side, in addition to encoding the message itself, you would need to use the WebOperationContext to apply the appropriate Content-Encoding: gzip header. Unfortunately you cannot do this within the MessageEncoder implementation itself because it's too late in the process because by the time the MessageEncoder is asked to write the message contents the message frame, in this case the HTTP headers, has already been written. So, you would also need additional behavior, in the form of an IOperationBehavior, applied to your operations that sets the headers accordingly.

Drew Marsh
Thats not really custom message encoding, as it just uses gzip as it's encoder..
Earlz
Of course. Sorry, typo, I meant to write "message encod*er*", not "message "encod*ing*".
Drew Marsh