VS2010: Configuration problem when using user controls in WCF: "Could not find default endpoint element that references contract 'ServiceReference1.IService"
Friday, September 14, 2012 8:11 AM
I have seen this question posted a lot here, but still I have found an answer that helped me, so now I try posting it myself.
I have a WCF-solution consisting of a WCF-server, a dll-file, which contains the communication with the WCF-serer (I will call it the comm-file here) and an exe-file containing a form to show some data from the server and that works well with no communication-issues.
I then add a project containing a usercontrol and give it a reference to the comm-file (It still works) and add the usercontrol to the form in my exe-file and it still works.
But as soon as I define and instanciate a variable of type comm-file it stops working and I get the error-message below:
Could not find default endpoint element that references contract 'ServiceReference1.IService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
If I remove the variable everything works fine again, so it seems that there is nothing wrong with the .config-files, so I would guess that it thinks thinks that it is missing a .config-file, but where? the comm-file has an app.config, the exe-file had when the problem started, and it doesn't make sense that the usercontrol should have a .config-file. So what is missing?
- Changed Type LeoTangModerator Sunday, September 23, 2012 2:51 PM
Monday, September 17, 2012 10:51 AMModerator
->If I remove the variable everything works fine again, so it seems that there is nothing wrong with the .config-files, so I would guess that it thinks thinks that it is missing a .config-file, but where? the comm-file has an app.config, the exe-file had when the problem started, and it doesn't make sense that the usercontrol should have a .config-file. So what is missing?
System.Configuration does not support config files for libraries, the content of the config file must be added to the host's app.config file. In this case, you must add the content of the app.config in the comm-file to App.config file of the exe-file.
Monday, September 17, 2012 7:55 PMSince I wrote my question, I have added the config-file to my config file of my exe-file. The two config-files are identical.
I originally had a config-file for both projects, which were identical and autogenerated, and this is what I have recreated, so it's back to the autogenerated files.
I have discovered that the usercontrols does not work for me even if I create them in the exe-file itself, where they give the exact same errormessage as when I put them in their own project as soon as I define a variable from the comm-project like this:
GuiCommunication.Communication comm = new GuiCommunication.Communication();
So I can't get any usercontrol to reference other projects, which I'm certain should be possible. The errormessage speaks of two possible causes of the error:
1. the config-file is missing. But the exe-file has a config which also enables WCF-communication, so it seems, that it would be enough.
2. no matching endpoint found. But neither the exe-file or the usercontrol has any WCF-communication, so how could that matter?
So while one of the problems above should cause my error, I can't see which or why. I hope someone can help me solve my problem.
Wednesday, September 19, 2012 9:30 AMModerator
What is the usercontrol you refer to? Could you please upload the projects somewhere(e.g SkyDrive) so that we can download it to reproduce this issue.
In addition, I'd suggest your run Process Monitor, isolate App.config to see where it tried to load config files.
Monday, September 24, 2012 12:22 PM
I have now uploaded my two projects to my Skyrive, where I hope they are available (it's my first visit to skydrive;
The wcf-folder is the server-part and the gui-server is everything else.
I have three projects on the GUI-site:
1: the GuiCommunication, which calls the web-server
2: the GUI which contains the actual windows Forms and calls GuiCommunication
3: the usercontrols, which reference GuiCommunication. This is currently not used since it creates my error, but it contains two usercontrols, which I would like to use in my GUI-project (in mainform.cs), but as soon as I add one to the form I get my error.
The solution is currently working as long as I don't add a usercontrol.
I hope the project is understandable and someone can tell me, what is wrong.Thanks.