如何通过 WSHttpBinding 安全性和 GZip 压缩来构建自定义绑定?
我在这里面临一个问题。 我正在做一个客户端/服务器项目,这是 WCF Web 服务调用来获取数据。由于传输的数据量很大,我必须以编程方式将绑定更改为自定义绑定(而不是通过配置文件)。
我正在创建一个新用户-定义绑定又称为自定义绑定。 该类的示例是:
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 能够正常工作。
i am facing a problem here.
I am doing a client/server project, which is WCF web service calling to get data.Due to huge data of transfering, i got to change my binding to custom binding programmatically(not by config file.)
I am creating a new user-define binding aka custom binding.
example of the class is :
public class MyCustomBinding : CustomBinding
and override a function 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;
}
what i am trying to do is copy all setting from wshttpbinding, and add on gzip as the message encoder.
Compress an encrypted data will lead to a bigger size of the original data size.
this is because the SymmetricSecurityBindingElement from WSHttpBinding did the encryption.
How to do this in correct way? i want the security setting from wshttpbinding, and also the gzip to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用一种行为来相应地应用压缩:
http://weblogs.asp.net/cibrax/archive/2006/03/29/441398.aspx
编辑:我也许还应该包含基于行为的压缩的链接:
http://weblogs.shockbyte.com.ar/rodolfof/archive/2006/04/ 06/5632.aspx
You should be able to just use a behavior to apply compression accordingly:
http://weblogs.asp.net/cibrax/archive/2006/03/29/441398.aspx
EDIT: I perhaps should also include the link to the Behavior based compression:
http://weblogs.shockbyte.com.ar/rodolfof/archive/2006/04/06/5632.aspx