The Error
Service ‘Namespace.ServiceName’ 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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Service ‘Namespace.ServiceName’ 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.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[InvalidOperationException: Service ‘Namespace.ServiceName’ 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.] System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreApplicationEndpoints(ServiceDescription description) +345 System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +292 System.ServiceModel.ServiceHostBase.InitializeRuntime() +90 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +175 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +740 System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +125 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +901 [ServiceActivationException: The service ‘/ServiceDirectory/ServiceName.svc’ cannot be activated due to an exception during compilation. The exception message is: Service ‘Namespace.ServiceName’ 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..] System.Runtime.AsyncResult.End(IAsyncResult result) +624522 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +196075 System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +166
When are you likely to get this
This appears frequently when setting up new WCF services, or changing namespace or service names of existing ones. Unless, you’re a machine and never mistype anything, that is.
The cause
This is caused by a configuration error in the web.config. In my experience, it’s always caused by this; even if you’re sure that you’ve got it configured right - you haven’t.
Resolution
1. Check that the web.config has an endpoint defined:
<service behaviorConfiguration="commonBehavior" name="Namespace.ServiceName">
<endpoint binding="..." contract="Interface.IServiceName"/>
</service>
2. Check the spelling. Compare the namespace against the service.svc file:
<%@ ServiceHost Service="Namespace.ServiceName" %>
3. Make sure you have the namespace specified in the web.config. The easiest way to determine why a WCF service is not working is navigating to the service.svc in internet explorer.
4. Don't forget to do an IISReset if you change the web.config.