I have created a WCF service, basically it does some interaction with my database.
The service is in a project, and it calls functions from a library that i created in another project.
In my library, which i will call WCFSerivceLibrary i also have an app.config which i want to pull out some stored values in the AppSettings section.
The issue is that when i call my WCF service from a certain client, and a function is executing in the WCFServiceLibrary, whenever i call AppSettings it checks the configuration
file for the calling client!
Further Explanation :
lets say we have a windows forms application which calls my WCF service this way :
MyWCFService.DoWork();
in the function DoWork in my WCF service i have the following code :
Type DoWork ()
{
//MyWCFServiceLibrary is a library in the same solution of the WCF Service.
MyWCFServiceLibrary.DoWorkOne();
MyWCFServiceLibrary.DoWorkTwo();
}
In the functions DoWorkOne or DoWorkTwo… I’m calling on AppSettings to get some values stored in the app.config of MyWCFServiceLibrary project, but instead, on execution the AppSettings are loaded from the app.cofing of my windows forms client calling the WCF service.
- How to avoid the mentioned issue above?
- Can I have a single configuration file for my WCF Service and the service library?
- How to share it between both?
I’m writing below what I meant about copying the configuration. But I don’t think that this is the problem. The problem is probably that you’re not even doing WCF communication. I suspect that you included the DLL both in the service project and the client project and you’re simple calling the methods on class from the client.
Do do WCF communication you need to have the WCF service running (for example an EXE that creates a
ServiceHostwith an endpoint). Then in the client, you add a service reference by using Visual Studio’s “Add service reference” menu item.There’s no need to include the DLL in the client, as classes will be generated automatically to access the service via WCF.
Now for using application settings properly:
Copy the application settings of your DLL’s
app.configfile to theapp.configfile of the executable project that’s using the DLL. For example, this could then look like this:After doing that, the application can access its settings through
Properties.Settings.Default.Test(which returnsTestvalue EXE) and the DLL can access its settings throughProperties.Settings.Default.Test(which returnsTestvalue DLL).I don’t understand why people need to use things like
ConfigurationManagerwhen it is actually that simple…