当以编程方式更新 wcf 服务的 web.config 时,可以通过执行...添加行为
ServiceModelSectionGroup secgroup = (ServiceModelSectionGroup)_webConfig.GetSectionGroup("system.serviceModel");
ServiceBehaviorElement SerBeh3 = new ServiceBehaviorElement();
SerBeh3.Name = "AuthenticationSvcWrapBehavior";
secgroup.Behaviors.ServiceBehaviors.Add(SerBeh3);
我的问题是如何添加绑定(bind)部分?
我想要做的就是创建一个具有名称、模式和 Transport.ClientCredentialType 的绑定(bind),然后将 BindingConfiguration 设置为端点的所述名称。
最佳答案
我想出了如何在配置中添加绑定(bind)部分。也许我很笨,但我认为有关配置更改的文档很烂......
//Update Service model for wcf services
ServiceModelSectionGroup secgroup = (ServiceModelSectionGroup)_webConfig.GetSectionGroup("system.serviceModel");
//Add the binding section with the settings that enable HTTPS communications
secgroup.Bindings.BasicHttpBinding.Bindings.Add(CreateBasicHttpBinding("SecureWebBinding",
BasicHttpSecurityMode.Transport,
HttpClientCredentialType.None));
private BasicHttpBindingElement CreateBasicHttpBinding(string name, BasicHttpSecurityMode mode, HttpClientCredentialType credentialType)
{
BasicHttpBindingElement basicHttpBinding = new BasicHttpBindingElement();
basicHttpBinding.Name = name;
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.Transport;
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
return basicHttpBinding;
}
关于c# - 如何以编程方式将 wcf 绑定(bind)部分添加到 web.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4249277/