除了遍历所有属性和设置值之外,有没有从BasicHttpBindingElement创建BasicHttpBinding的简单方法?
这就是我现在正在做的事情
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;
}
}发布于 2014-09-25 06:21:24
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
发布于 2014-06-11 04:08:29
使用接受名称的重载,并在配置文件中对其进行命名。这样您就不必手动访问元素了。
https://stackoverflow.com/questions/24149937
复制相似问题