简体   繁体   English

ADO.NET数据服务的数据压缩

[英]Data compression for ADO.NET data services

I have an ADO.NET data service exposed by a .NET app (not IIS) which is consumed by a .NET client app. 我有一个.NET应用程序(不是IIS)公开的ADO.NET数据服务,它由.NET客户端应用程序使用。 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. 我想在线上压缩XML数据以减少有效负载并提高性能。 Is this possible? 这可能吗?

I assume you're hosting using WCF in your .NET "app"? 我假设您在.NET“应用程序”中使用WCF进行托管 If so, you would need write some custom MessageEncoder implementation because WCF does not provide this out of the box. 如果是这样,您需要编写一些自定义MessageEncoder实现,因为WCF不提供开箱即用的功能。 Luckily there is a sample in the SDK that you can use. 幸运的是,您可以使用SDK的示例

I actually just realized that this is only step one of two depending on whether or not your client is also WCF? 我实际上只是意识到这只是两个步骤之一,取决于您的客户端是否也是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. 虽然这将对消息进行编码,但它需要您的客户端使用类似配置的解码器,因为该实现不会设置向“纯”HTTP客户端发出编码信号所必需的HTTP头。 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. 因此,如果它不是另一侧的WCF客户端,除了对消息本身进行编码之外,您还需要使用WebOperationContext来应用适当的Content-Encoding: gzip头。 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. 遗憾的是,你不能在MessageEncoder实现本身中这样做,因为它在这个过程中为时已晚,因为当MessageEncoder被要求写入消息内容时,消息帧(在这种情况下是HTTP头)已经被写入了。 So, you would also need additional behavior, in the form of an IOperationBehavior , applied to your operations that sets the headers accordingly. 因此,您还需要以IOperationBehavior的形式应用于相应设置标头的操作的其他行为。

您可以使用GZipStream对其进行压缩和解压缩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM