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

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

问题描述

我有一个具体的要求,删除所有客户端WCF配置(小于system.serviceModel>)开出主app.config文件,并到一个单独的XML文件。我想看到的行为类似于可使用文件=指令appSettings部分。其实,我最想要的是能够为每一个消费服务指定单独的文件...

我知道我可以建立一个自定义的ChannelBuilder工厂从XML文件(或一组人)读取配置数据,但我会preFER自动发现通过客户端仍然有配置数据。

一些基本的谷歌搜索似乎表明这是不可能的,但我想从这么获取视图 - 有谁知道这里的​​东西我一直没能找到? :)

  

:

     

蒂姆·斯科特和davogones双方想出了一个可能的建议,但其中一个依赖于分裂system.serviceModel部分的组成部件出单独的文件。虽然这不是我看上去很什么(我想定义每个服务及其相关的元素离散,每个服务一个文件),它的的一个选项。我会调查,让你知道我的想法。

解决方案

我有一种倾向,编程方式配置所有的服务设置。

我的客户是不是真的类型来理解XML,并要求我做出的配置文件更像旧INI风格。

这是容易做到的(阅读不包含INI文件code):

  //创建URI被用作服务端点
        乌里tcpBaseAddress =新的URI(
                的String.Format(的net.tcp:// {0}:{1},
                    LocalIPAddress.ToString(),GeneralPortNumber));

        //创建通过net.tcp的服务端点绑定
        NetTcpBinding的ntcBinding =新NetTcpBinding的();
        ntcBinding.Security.Mode = SecurityMode.None;
        System.ServiceModel.Channels.Binding tcpBinding = ntcBinding;

        //创建服务宿主,并添加端点
        主机=新的ServiceHost(typeof运算(WordWarService),tcpBaseAddress);
 

既然我们可以配置主机(和客户端,对于这个问题)编程有什么让你从任何你选择的方式提供的设置(数据库,XML,疯狂的文本文件,等等)。

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...

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.

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? :)

Edit ::

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.

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

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);

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天全站免登陆