I recently created a WCF service (dll) and a service host (exe). I know my WCF service is working correctly since I am able to successfully add the service to WcfTestClient.
However, I seem to be running into an issue when I comes to utlizing my WCF from a service host (exe). I can add a reference to the WCF (dll) to my service host (exe) and create the necessary componets to the exe; such as the service installer, service host, and the app.config, compile and then finally install the exe using InstallUtil. But, when I tried to start the service in the Microsoft Management Console, the service immediately stops after being started.
So I began investigating what could exactly be causing this issue an came up with this error from the Application Log in the Event Viewer.
Description:
Service cannot be started. System.InvalidOperationException: Service 'Service' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
This error is actually generated in the OnStart
; of my exe, when I perform this call ServiceHost.Open()
. I've seen numerous posts where other individuals have run into this issue, however most if not all of them, claim that the service name or contract; namespace and class name, are not being specified. I checked both of these entries in my config file; in the exe as well as in the dll, and they match up PERFECTLY. I've had other people in the office double check behind me to make sure I wasn't going blind at one point, but of course they came to the same conclusion as me that everything looked like it was specified correctly. I am truly at a lost as to what is going on at this point. Could anyone help me with this issue?
Another thing that came up as a possible reason this may be happening is that the app.config is never being read; at least not the one I think should be getting read. Could this be the issue? If so, how can I go about addressing this issue. Again, ANY help would be appreciated.
To prepare the configration for WCF is hard, and sometimes a service type definition go unnoticed.
I wrote only the namespace in the service tag, so I got the same error.
Do not forget, the service tag needs a fully-qualified service class name.
For the other folks who are like me.
One crucial thing to remember for those working with a Console application to host the WCF service is that the Web.config file in the WCF project is completely ignored. If your
system.serviceModel
configuration is there, then you need to move that section of config to the App.config of your Console project.This is in addition to the answers concerning ensuring the namespace is specified in the right places.
I had this error in a Windows Service when my WCF Service Library that I created was not connected for hosting, but was connected for connection. I was missing an endpoint. (I wanted both connection and hosting in my Windows Service so that I could serve up the WCF Service to other connections, as well as have the main process of my Windows Service use it as well to do various tasks on a timer/schedule.)
The fix was that I rightlcicked my App.config file and chose Edit WCF Configuration. Then, I did the steps for Create Service so that I could connect to my WCF Service. Now I had two endpoints in my App.config, not just one. One endpoint was for the connection to the WCF Service Library, and another was for the hosting of it.
Today i ran into same issue, posting here my mistake and correction of it so that it may help someone.
While Re-structuring code, I had actually changed Service class and IService names and changed ServiceHost to point to this new Service class name (as shown in code snippet) but in my host applications App.Config file i was still using old Service class name.(refer config section's name field in below snippet)
Here is the code snippet,
and in App.config file under section services i was referring to old serviceclass name , changing it to New ServiceClassName fixed issue for me.
Just copy the App.config file from the service project to the console host application and paste here and then delete it from the service project.
I just worked through this issue on my service. Here is the error I was receiving:
Here are the two steps I used to fix it:
Use the correct fully-qualified class name:
Enable an endpoint with mexHttpBinding, and most importantly, use the IMetadataExchange contract: