1. 创建wcf服务库
2. 宿主到web程序上
// 宿主wcf服务库 RouteTable.Routes.Add(new ServiceRoute("ctserver.dll", new WebServiceHostFactory(), typeof(DMService.DMService)));3. 注意事项:
- wcf服务程序需在服务类定义的头部增加
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]- web程序中的Web.config增加
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> </system.serviceModel>
4. 如何将wcf服务宿主到在现有的mvc: 路由里屏蔽关键字即可
routes.MapRoute("Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults , new { controller = @"^\b(?!ctserver.dll)\w*\b$" } );
参考文档:
云腾软件