Skip to main content
 首页 » 编程设计

c#之MVC Global.asax --> ServiceRoute/WebServiceHostFactory 类不存在

2024年08月06日28cmt

在我的 MVC 网站的 global.asax 中,我试图为 WCF 服务添加一个引用,根据我在网上找到的内容,我应该使用类似于以下内容的内容:

 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 
 ); 

但是,即使在声明 ServiceRoute 类正在使用命名空间 System.ServiceModel.Activation 之后,编译器仍然说这不是一个现有的类......

“WebServiceHostFactory”类也是如此……visual studio 问我是否要创建这个类……

我在这里缺少什么?

请您参考如下方法:

尝试:

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

详细原因可以在Answer中找到.