我遇到了一个问题。 我正在做一个客户端/服务器项目,它是 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/