none
Initializing WCF Client from a library dll RRS feed

  • Question

  • I have a WCF Client I wish to create/write in a .NET dll library.

    The Problem

    I properly consume the service when I create the library, however when I run the program I get the client endpoint not found error.

    I know what the problem is. 

    The WCF Client is looking in the App.Config file for the connection information.  As the information is in the dll, its looking in the wrong place.  This is problematic because we may swap out the WCF server as it will be running as an IIS server.  So we only want to have to update the library dll and not all the applications that may use it.

    The Question

    Is it possible to initialize the WCF Client from the dll .config?  I tried looking at the documentation and I don't see a place where I can load a config resource class into it during construction.

    I could always manually initialize it.  But that's a work around and not the optimal solution IMHO.

    Wednesday, June 25, 2014 7:02 PM

Answers

  • The WCF Client is looking in the App.Config file for the connection information. 

    No that is not corrrect. .NET looks for all configuration information in the root.config of the solition. Any subordnate app.configs that may have configuration information, like a classlib project that the root project has reference too must have its config information in its app.config at the project level copied to the root.config of the application at root project level.

    Any .NET solution that creates a programname.exe can have an app.config at the project level,  which is the root.config. So, this exe project has reference to a classlib project (a DDL) and the DLL will be created and the classlib project has an app.config that has to configuration. In this example, the app.config infromation at the classlib project level must be copied to the root app.config in the exe project, since the exe project is the root project. .NET is looking at the root.config for configuration information. .NET is not looking at anything else but in the root.config of the solution for configuration information. 

    Here is the kicker for you concering an exe type project that has an app.config. When the solution is compiled and it builds successfully, the app.config file is copied over to a runtime config file called programname.exe.config and placed at the same location as the progrogramname.exe is located. That's the file .NET is looking for at runtime is the runtime programname.exe.config. So you deploy that exe to another machine, then the programname.exe.config must be deployed to the same location too.  

    If an ASP.NET Web application, I don't care if it's a ASP.NET form UI application or a ASP.NET Web service WCF or not application and either one of them have reference to a classlib project and that classlib project has an app.config with configuration information, then the configuration information in the app.config must be copied to the Web.config, becuase the Web application is the root application and the Web.config is the root.config where .NET is going to look for configuration information.

    The only time an app.config is used is when running the application in VS with using debug mode.

    Capiche?

    Wednesday, June 25, 2014 8:35 PM