开发者

Have an ASP.Net application and a exe, and I don't want two configuration files

I have exe library project. This project is brought in as a reference in my web app, which has all of the same configuration elements in it's own config. Light calls are made directly to the classes in the exe project on an in-process basis, but heavy (gigabytes of memory usage) calls are made through the command line.

I have the following configuration elements duplicated into an AppName.config file, as well as the Web.config file:

<configuration>
<appSettings>
    ...
</appSettings>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding ... />
            <readerQuotas ... />
            <security>...</security>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint ... />
    </client>
</system.serviceModel>

The appSettings are开发者_JAVA技巧 relatively easy, as that can be delegated to an outboard config file. The service model binding is not, as it cannot be delegated. The only two ways I can think of are:

1) Configure the channel for the app in command-line mode by looking for web.config in current, parent, parent (etc) directories, and load it up into a XmlDocument, and grab attributes and set it on the channel properties directly.

2) Before calling the exe in the web app, grab the appSettings and system.serviceModel elements out of the parent Web.config, and write them into the AppName.config file if Web.config is newer. However, my exe is in the apps Bin directory due to shared dll's, and writing to /Bin will forcibly restart my web app.... ouch.

Many of my channel properties are important, and cannot be the defaults. Is there a better way?


If you use Visual Studio you can add existing file from other project and use "Add as link".


IIRC, you can use configSource on both of those sections (here - note that it works on the levels below system.serviceModel). This gives you more files, but you should be able to share some data between client and server. However, it may not be necessary or desirable to share some of the config down to the client - personally I would be tempted to just leave it as-is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜