gpt4 book ai didi

c# - 如何以编程方式将 wcf 绑定(bind)部分添加到 web.config

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:53 25 4
gpt4 key购买 nike

当以编程方式更新 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com