首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从BasicHttpBindingElement创建BasicHttpBinding

从BasicHttpBindingElement创建BasicHttpBinding
EN

Stack Overflow用户
提问于 2014-06-11 04:05:16
回答 2查看 1.2K关注 0票数 0

除了遍历所有属性和设置值之外,有没有从BasicHttpBindingElement创建BasicHttpBinding的简单方法?

这就是我现在正在做的事情

代码语言:javascript
复制
public class BasicHttpBinding : System.ServiceModel.BasicHttpBinding
{
    public BasicHttpBinding(BasicHttpBindingElement element)
    {
        this.AllowCookies = element.AllowCookies;
        this.BypassProxyOnLocal = element.BypassProxyOnLocal;
        this.CloseTimeout = element.CloseTimeout;
        this.HostNameComparisonMode = element.HostNameComparisonMode;
        this.MaxBufferPoolSize = element.MaxBufferPoolSize;
        this.MaxBufferSize = element.MaxBufferSize;
        this.MaxReceivedMessageSize = element.MaxReceivedMessageSize;
        this.Name = element.Name;
        this.OpenTimeout = element.OpenTimeout;
        this.ProxyAddress = element.ProxyAddress;
        this.ReceiveTimeout = element.ReceiveTimeout;
        this.Security.Message.AlgorithmSuite = element.Security.Message.AlgorithmSuite;
        this.Security.Message.ClientCredentialType = element.Security.Message.ClientCredentialType;
        this.Security.Mode = element.Security.Mode;
        this.SendTimeout = element.SendTimeout;
        this.TextEncoding = element.TextEncoding;
        this.TransferMode = element.TransferMode;
        this.UseDefaultWebProxy = element.UseDefaultWebProxy;
    }
}
EN

回答 2

Stack Overflow用户

发布于 2014-09-25 06:21:24

代码语言:javascript
复制
var bindingConfig = ConfigurationManager.GetSection("system.serviceModel/bindings") as System.ServiceModel.Configuration.BindingsSection;
        var element = bindingConfig.BasicHttpBinding.ConfiguredBindings[2]; //Whatever index the binding you want is.
        var myBinding = (System.ServiceModel.Channels.Binding)Activator.CreateInstance(bindingConfig.BasicHttpBinding.BindingType);
        element.ApplyConfiguration(myBinding);//This is what adds the configuration to the binding.

这是我在上面找到它的地方:http://weblogs.asp.net/cibrax/getting-wcf-bindings-and-behaviors-from-any-config-source

票数 1
EN

Stack Overflow用户

发布于 2014-06-11 04:08:29

使用接受名称的重载,并在配置文件中对其进行命名。这样您就不必手动访问元素了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24149937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档