Dryadwoods Dryadwoods - 3 months ago 26
C# Question

MVC Global.asax --> ServiceRoute / WebServiceHostFactory class does not exist

Inside the global.asax of my MVC website I am trying to add a reference for a WCF Service, according to what I found online, I should use something similar to:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.Add(new ServiceRoute("Person", new WebServiceHostFactory(), typeof(PersonService)));

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);


But, even after saying that the class
ServiceRoute
is using the namespace System.ServiceModel.Activation, the compiler still says that is not an existing class.....

The same happens to the class "
WebServiceHostFactory
"... visual studio ask me if I want to create this class......

What am I missing in here?

tom tom
Answer

Try:

 routes.Add(new ServiceRoute("Person", new ServiceHostFactory(), typeof(namespace.PersonService)));

Detailed reason is found in this Answer.