[转] 关于 WCF 中数据压缩的几篇文章

原文:http://www.cnblogs.com/jiabao/archive/2007/12/04/982534.html
在.net3.0出现以前我们进行分布式开发式有两个选择一个是webservice,另一个是remoting;

在早期的项目中,比较喜欢remoting,因为remoting可控性好,也好部署,不需要依赖其他的宿主环境。 今年的做的项目大部分都是webservice的,因为在这几年remoting过程中遇到了几个问题,比较典型的就是remoting的宿主程序容易出现异常,并且这个异常很难捕捉,一旦宿主程序的压力过大,就会出现这个情况。比较脸红的是,这个问题到现在也没有发现是怎么产生的,也就无从说解决了

凡是涉及到分布式部署的项目都会有数据的传输问题:要对需要传输的数据进行压缩。较早的项目中,都是将dataset压缩为流对象(经过序列化的)后进行传递的,压缩比1/4的样子。

.net3.0的出现极大的方便了分布式项目的开发部署,在学习wcf时候,一直在寻找在wcf构架下的数据压缩方案,就将搜集到一些文章汇总在这里(这方面的东西少的可怜),供大家参考。个人比较喜欢 WS-Compression for WCF 感觉思路更清晰

ms的文章:Custom Message Encoder: Compression Encoder
http://msdn2.microsoft.com/en-us/library/ms751458.aspx,例子在TechnologySamples、Extensibility、Channels、MessageEncoder、Compression目录中

msdn社区的文章: Serialize Datasets as binary (not XML) in WCF
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1618046&SiteID=1&pageid=0#1648392
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1520385&SiteID=1,这里面 Pablo Cibraro 的回复非常清晰,俺就摘录在这里了

There are basically three ways to implement compression in WCF.

1. At transport level using a message encoder which compress all the data throughout the entire channel (From the client to the service). There is a sample of this in the WCF SDK,  [SDK Folder]TechnologySamples/Extensibility/MessageEncoder/Compression

2. At message level, adding some metadata to the soap message (Soap headers) and compressing the soap body. This approach can use a WCF binding or a MessageInspector Behavior to modify the soap messages. You can find an example here, http://weblogs.asp.net/cibrax/archive/2006/03/29/WS_2D00_Compression-for-WCF.aspx

3. Only for the Http transport, you can use the Http Compression capability. I haven't seen any implementation of this technique so far.

I hope this can help you

Regards,

Pablo.

 

WS-Compression for WCF
http://weblogs.asp.net/cibrax/archive/2006/03/29/441398.aspx


继续补充中...



--畅所欲言,随心而谈--
本博客文章全部原创,转载请注明出处,谢谢
版权所有 jiabao.cnblogs.com 转载请联系
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你希望通过 WCF 接收 `uni.uploadFile` 的数据,而不仅仅是文件,你可以按照以下步骤进行操作: 1. 在 WCF 服务的契约,定义一个操作合同,用于接收文件数据。可以使用 `byte[]` 类型的参数来接收数据。例如: ```csharp [ServiceContract] public interface IFileService { [OperationContract] void UploadFileData(byte[] fileData); } ``` 2. 在服务实现类,实现该操作合同,并将 `byte[]` 类型的参数用于处理数据。例如: ```csharp public class FileService : IFileService { public void UploadFileData(byte[] fileData) { // 处理文件数据 // 可以进行自定义操作,如保存到数据库、解析数据等 } } ``` 3. 在服务的配置文件,配置绑定和终结点。可以使用基于 HTTP 的绑定,如 `basicHttpBinding` 或 `webHttpBinding`。例如: ```xml <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IFileService" /> </basicHttpBinding> </bindings> <services> <service name="YourNamespace.FileService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFileService" contract="YourNamespace.IFileService" /> </service> </services> </system.serviceModel> ``` 4. 在客户端调用代码,引用服务契约并创建代理对象。然后,可以使用代理对象调用 `UploadFileData` 方法并传递数据。例如: ```csharp using (var client = new FileServiceClient()) { byte[] fileData = Encoding.UTF8.GetBytes("Your file data"); client.UploadFileData(fileData); } ``` 这样,你就可以在 WCF 成功接收 `uni.uploadFile` 的数据。记得根据实际需求进行适当的异常处理和数据操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值