Search code examples
c#asp.net-mvcwcfwcf-client

WCF Client Implementation, is there way to keep services and end-point detail in class library app.config rather then web.config for ASP.NET MVC app


I have .NET project in which I have APP.Client.Proxy class library project, responsible to implement WCF for client side so all the services and end-point configuration details are there and then I have another ASP.NET MVC project using these services implementation i.e. from controller. Now if I put services and end-point detail in app.config for class library project then it do not work, complaining about cannot find end-point but do work if I put end-point configuration detail in web.config for MVC web application.

My question is there way that I keep the services and end-point detail separate in app.config in class library rather then web.config


Solution

  • The app domain uses one config file when executing. while app setting and connection strings sections allow for referencing external file and configSource respectively.

    After some quick GoogleFu I cam across these two articles

    http://weblogs.asp.net/cibrax/configsource-attribute-on-system-servicemodel-section

    https://blogs.msdn.microsoft.com/youssefm/2009/11/03/separating-out-wcf-configuration-into-multiple-files-with-configsource/

    The crux of it is that you cannot leave it in the class library config but you can still separate them out into external config files.

    <configuration>
      <!-- other code removed for brevity -->  
      <system.serviceModel>
        <services configSource="Services.config" >
    
        </services>
        <bindings configSource="Bindings.config">
    
        </bindings>
        <behaviors configSource="Behaviors.config">
    
        </behaviors>
      </system.serviceModel>
      <!-- other code removed for brevity -->
    </configuration>