首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

使用ConfigurationManager加载System.ServiceModel配置节

作为一个云计算领域的专家,我可以告诉您,使用ConfigurationManager加载System.ServiceModel配置节是一种在.NET框架中配置WCF(Windows Communication Foundation)服务的方法。

在WCF服务的配置文件中,System.ServiceModel配置节包含了服务的各种配置信息,例如绑定、行为、服务终结点等。使用ConfigurationManager类加载System.ServiceModel配置节可以方便地读取这些配置信息,并将其应用于WCF服务。

以下是一个使用ConfigurationManager加载System.ServiceModel配置节的示例代码:

代码语言:csharp
复制
using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Configuration;

// 加载System.ServiceModel配置节
ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));

// 获取服务终结点配置
ServiceEndpointCollection serviceEndpoints = serviceModelSectionGroup.Services.Services["MyService"].Endpoints;

// 创建服务主机
ServiceHost serviceHost = new ServiceHost();

// 添加服务终结点
foreach (ServiceEndpointElement serviceEndpointElement in serviceEndpoints)
{
    serviceHost.AddServiceEndpoint(Type.GetType(serviceEndpointElement.Contract), new BasicHttpBinding(serviceEndpointElement.BindingConfiguration), serviceEndpointElement.Address);
}

// 打开服务主机
serviceHost.Open();

在这个示例中,我们首先使用ConfigurationManager.OpenExeConfiguration方法打开配置文件,并使用ServiceModelSectionGroup.GetSectionGroup方法加载System.ServiceModel配置节。然后,我们可以使用ServiceModelSectionGroup对象的Services属性获取服务配置,以及使用ServiceEndpointCollection对象的Endpoints属性获取服务终结点配置。最后,我们可以使用ServiceHost对象的AddServiceEndpoint方法添加服务终结点,并使用Open方法打开服务主机。

推荐的腾讯云相关产品和产品介绍链接地址:

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

.Net2.0 使用ConfigurationManager读写配置文件

.net1.1中如果需要灵活的操作和读写配置文件并不是十分方便,一般都会在项目中封装一个配置文件管理类来进行读写操作。...而在.net2.0中使用ConfigurationManager 和WebConfigurationManager 类可以很好的管理配置文件,ConfigurationManager类在System.Configuration...根据MSDN的解释,对于 Web 应用程序配置,建议使用 System.Web.Configuration.WebConfigurationManager 类,而不要使用 System.Configuration.ConfigurationManager...下面我给出一个简单的例子说明如何使用WebConfigurationManager操作配置文件:    //打开配置文件    Configuration config = WebConfigurationManager.OpenWebConfiguration...value" />         修改和删除节点或属性也非常方便:    //打开配置文件

35720

WCF服务的批量寄宿

[源代码从这里下载] 我想很多人想到了直接读取表示寄宿服务的//配置元素列表,通过其name配置属性得到表示服务的“类型”...,让该名称表示成服务类型全名,但是由于它并包含程序集名称,我们往往不得不加载所有可用的程序集。...我们可以将需要需要批量寄宿的服务类型定义在配置文件中。很多人喜欢直接采用作为自定义的配置,但是我个人是既不推荐这种做法的,我觉得自定义结构化的配置是更好的选择。...Artech.BatchingHosting.BazService, Artech.BatchingHosting"/> 5: 上面XML表示的自定义配置通过具有如下定义的...在构造函数中,我们通过加载BatchingHostingSettings配置的方式获取需要批量寄宿的服务类型,并为之创建ServiceHost。

512100

第四,Springboot加载指定配置文件@PropertySource的使用

@PropertySource:加载指定的配置文件; 因为当我们把所有配置文件都放在全局的配置文件 中时会导致配置文件过多,所以我们可以根据业务逻辑把配置文件分开来放 本次做了一个测试,当自定义配置文件后缀为...yml时会导致注入失败,下面请看测试结果 1.yml方式 配置文件 persion.yml name: zhangsan age: 20 isBoss: false birth: 2018...Persion{name='null', age=null, isBoss=false, birth=null, maps=null, lists=null, dog=null} 2.properties方式 配置文件... persion.properties # 配置persion # idea 默认UTF-8 persion.name=张三 persion.age=18 persion.birth=2018/02/11...Feb 11 00:00:00 CST 2018, maps={k2=v2, k1=v1}, lists=[1, 2, 3], dog=Dog{name='dog', age=15}} 总结 自定义配置文件目前只支持

2.3K31

实现WCF和Unity 的集成

using System.Text; using Microsoft.Practices.Unity; using System.ServiceModel.Dispatcher; using System.ServiceModel...第三步:创建自定义的增加新的Behavior的 Service Host ServiceHost 提供了基本的“加载服务,配置endpoints,应用安全设置以及启动监听请求”机制。...但在Web的.svc中,ServiceHost是动态创建的,没有显示的指定ServiceHost的Factory,那它在默认情况下是使用ServiceHostFactory的,而ServiceHostFactory...产生的是ServiceHost对象,想要使用我们上一步中自定义的UnityServiceHost ,需要实现一个自定义的ServcieHostFactory,实现代码非常简单: using System...            //configure container             UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection

86180

C# 读写App.config配置文件的方法

一、配置文件概述: 应用程序配置文件是标准的 XML 文件,XML 标记和属性是区分大小写的。它是可以按需要更改的,开发人员可以使用配置文件来更改设置,而不必重编译应用程序。...配置文件的根节点是configuration。我们经常访问的是appSettings,它是由.Net预定义的配置。我们经常使用配置文件的架构是客诉下面的形式。...//配置声明                //定义配置组                        //配置组中的配置声明 <appSettings...使用 System.Configuration.ConfigurationManager,需要在工程里添加对 system.configuration.dll 程序集的引用。...如果希望写入配置文件,可以使用ConfigurationManager对象执行打开配置文件的操作后,将会返回一个Configuration的对象,利用该对象进行操作(增删改查都可以哦)。

7.3K90
领券