Monday, July 9, 2018

WCF Error - SOLVED - Service Attribute value could not be found in ServiceHost directive


In this article we take care of the WCF Error  ' Service Attribute value could not be found in ServiceHost directive', after changing a WCF Service properties or configuration.


WCF Error - Service Attribute value could not be found in ServiceHost directive


 WCF Error - Service Attribute value could not be found in ServiceHost directive


The error is originated after you changed some properties on a WCF web service.
For example, you created a web service using a Visual Studio template, which sets a WCF service usually called "Service1".

You customized the service and, after everything seems OK, you realize that the name of the service  is inappropriate, and you change it and the class/interface behind it.
The web service stops working.
Now , the ERROR message says that the TYPE of the web service could not be found.
The clue here is that could not be found in the "ServiceHost" directive.
You take a look at the classes in your project, but can't see the Service Host:

WCF Error - Service Attribute value could not be found in ServiceHost directive

Perform a search inside your project, looking for the "ServiceHost", and add "@" to the search since we're talking about an MVC Directive:

WCF Error - Service Attribute value could not be found in ServiceHost directive
 You'll find a small HTML file with the Directive: this is the markup which enables a hosting of your web service at the development stage:


WCF Error - Service Attribute value could not be found in ServiceHost directive

As you can see, when you renamed your service, Visual Studio updated the change of the name at the CodeBehind attribute, but didn't automatically renamed the TYPE exposed by the web service, in our example "RestService" instead of "Service1":

WCF Error - Service Attribute value could not be found in ServiceHost directive

So, change the Service to the one you wish, and run it:

WCF Error - Service Attribute value could not be found in ServiceHost directive
 Now you get it in JSON WebMessageFormat. If you wanted XML, just don't set any ResponseFormat, and you'll get the XML default format for WCF web services:

WCF Error - Service Attribute value could not be found in ServiceHost directive

WCF Error - Service Attribute value could not be found in ServiceHost directive



That's all!!!!


By Carmel Shvartzman

עריכה: כרמל שוורצמן