WCF 配置 - 从 app.config 中拆分出来 [英] WCF Configuration - Split it out of app.config

查看:36
本文介绍了WCF 配置 - 从 app.config 中拆分出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定要求,将所有客户端 WCF 配置 (<system.serviceModel>) 从主 app.config 文件中删除,并放入一个单独的 XML 文件中.我希望看到的行为类似于使用 File="" 指令的 appSettings 部分中可用的行为.事实上,我希望能够为每个使用的服务指定一个单独的文件......

I have a specific requirement to remove all client WCF configuration (<system.serviceModel>) out of the main app.config file, and into a separate XML file. The behaviour I would like to see is similar to that available in the appSettings section using the File="" directive. In fact, I'd ideally like to be able to specify a separate file for each consumed service...

我知道我可以构建一个自定义 ChannelBuilder 工厂,该工厂从 XML 文件(或一系列文件)读取配置数据,但我更愿意让客户端自动发现"配置数据.

I know I can build a custom ChannelBuilder factory that reads config data from an XML file (or a series of them), but I would prefer to still have the config data "auto-discovered" by the client.

一些基本的谷歌搜索似乎表明这是不可能的,但我想从 SO 那里得到观点 - 这里有人知道我找不到的东西吗?:)

Some basic Google searches seem to suggest this is not possible, but I wanted to get the view from SO - does anyone here know something I haven't been able to find? :)

:

Tim Scott 和 davogones 都提出了一个可能的建议,但该建议依赖于将 system.serviceModel 部分的组件部分拆分为单独的文件.尽管这不是我想要的(我想离散地定义每个服务及其关联元素,每个服务一个文件),但它是一种选择.我会调查并告诉你我的想法.

Tim Scott and davogones both came up with a possible suggestion, but one which relies on splitting the component sections of the system.serviceModel section out to separate files. Although this isn't quite what I'm looking for (I'd like to define each service and its associated elements discretely, one file per service), it is an option. I'll investigate and let you know what I thought.

推荐答案

我倾向于以编程方式配置我的所有服务设置.

I have a tendency to programatically configure all my service settings.

我的客户并不是真正理解 XML 的类型,并要求我制作更像旧 INI 样式的配置文件.

My clients aren't really the type to understand XML and have asked me make configuration files more like the old INI style.

这很容易做到(不包括读取 INI 文件代码):

This is easy to do (reading INI file code not included):

        // create the URI which is used as the service endpoint
        Uri tcpBaseAddress = new Uri(
                string.Format("net.tcp://{0}:{1}",
                    LocalIPAddress.ToString(), GeneralPortNumber));

        // create the net.tcp binding for the service endpoint
        NetTcpBinding ntcBinding = new NetTcpBinding();
        ntcBinding.Security.Mode = SecurityMode.None;
        System.ServiceModel.Channels.Binding tcpBinding = ntcBinding;

        // create the service host and add the endpoint
        Host = new ServiceHost(typeof(WordWarService), tcpBaseAddress);

因为我们可以以编程方式配置主机(和客户端),所以没有什么可以阻止您以您选择的任何方式(数据库、xml、疯狂的文本文件等)提供设置.

Since we can configure the host (and client, for that matter) programatically there is nothing keeping you from supplying the settings in any manner you choose (database, xml, crazy text file, etc).

这篇关于WCF 配置 - 从 app.config 中拆分出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆