c# - 如何通过 WSHttpBinding 安全性和 GZip 压缩来构建自定义绑定(bind)?

标签 c# wcf gzip custom-binding

我遇到了一个问题。 我正在做一个客户端/服务器项目,它是 WCF Web 服务调用以获取数据。由于传输的数据量很大,我必须以编程方式(而不是通过配置文件)将我的绑定(bind)更改为自定义绑定(bind)。

我正在创建一个新的用户定义绑定(bind),也就是自定义绑定(bind)。 该类的示例是:

public class MyCustomBinding : CustomBinding    

并覆盖 BindingElementCollection 函数:

public override BindingElementCollection CreateBindingElements()
{
   WSHttpBinding wSHttpBinding = new WSHttpBinding("RMSKeberosBinding"); //this is to load the configuration from app.config. because i want to copy the setting of wsHttpConfig to my custom binding.

   BindingElementCollection wSHttpBindingElementCollection = wSHttpBinding.CreateBindingElements();

   TransactionFlowBindingElement transactionFlowBindingElement = wSHttpBindingElementCollection.Remove<TransactionFlowBindingElement>();
   SymmetricSecurityBindingElement securityElement = wSHttpBindingElementCollection.Remove<SymmetricSecurityBindingElement>();
   MessageEncodingBindingElement textElement = wSHttpBindingElementCollection.Remove<MessageEncodingBindingElement>();
   HttpTransportBindingElement transportElement = wSHttpBindingElementCollection.Remove<HttpTransportBindingElement>();

   GZipMessageEncodingBindingElement gzipElement = new GZipMessageEncodingBindingElement(); // this is from microsoft sample. i want to add gzip as a compress to my message.

   BindingElementCollection newCol = new BindingElementCollection();
   newCol.Add(transactionFlowBindingElement);
   newCol.Add(securityElement);
   newCol.Add(gzipElement);
   newCo .Add(transElement);
   return newCol;
}

我想做的是从 wshttpbinding 复制所有设置,并添加 gzip 作为消息编码器。 压缩加密数据会导致原始数据大小变大。 这是因为 WSHttpBinding 中的 SymmetricSecurityBindingElement 进行了加密。 如何以正确的方式做到这一点?我希望 wshttpbinding 的安全设置,以及 gzip 的工作。

最佳答案

您应该能够只使用一种行为来相应地应用压缩:

http://weblogs.asp.net/cibrax/archive/2006/03/29/441398.aspx

编辑:我也许还应该包含指向基于行为的压缩的链接:

http://weblogs.shockbyte.com.ar/rodolfof/archive/2006/04/06/5632.aspx

关于c# - 如何通过 WSHttpBinding 安全性和 GZip 压缩来构建自定义绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1537939/

相关文章:

ubuntu - 如何在 ubuntu 中提取 .tar 文件?

c# - 如何在 Xamarin Forms 中制作卡片样式的 ListView

c# - Protobuf.net WCF 反序列化列表<T>

php - 通过 PHP 解压缩 .gz 文件

wcf - 将 REST 服务部署到 Azure 是否有任何特殊的部署要求?

WCF 回调接口(interface) - 谁关闭 channel

c# - 如果 gzip 文件是通过组合多个 gzip 文件创建的,Chrome 不会解压缩 gzip 文件

c# - 如何修复 'cannot convert from method group to ' Func<AsyncCallback, object, IAsyncResult>'?

c# - jQuery Mobile Datebox 不会采用默认日期值 - 尝试了所有方法

c# - 使用 lambda 避免空检查