我已经找出问题所在了。首先,我丢失了注册路线的函数路径的一部分。修复该路径后,我能够在我的托管环境中显示我的 wsdl。然而,这搞乱了我所在区域的默认路由。因此,对于将来遇到此问题的任何人,这是我的解决方案:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
routes.MapRoute(
"CustomFunctions", // Route name
"{controller}/{action}/{id}", // URL with parameters
new
{
controller = "CustomFunctions",
action = "Index",
id = UrlParameter.Optional
}, // Parameter defaults
new { controller = "^(?!CustomFunctions).*" }
);
routes.Add(new ServiceRoute("CustomFunctions", new ServiceHostFactory(),
typeof(CustomFunctions)));
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Had to do some special stuff here to get this to work using a default area and no controllers/view in the root
routes.MapRoute(
name: "Default",
url: "{area}/{controller}/{action}/{id}",
defaults: new { area = "", controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "Viper.Areas.Home" }
).DataTokens.Add("area", "Home");
}
我主要指定了自定义路由,以便当我导航到指定的 url 时,它会显示我的 .svc 文件。我从 Global.asax.cs 中的 ApplicationStart 方法调用此方法。我还必须在我的主区域中为我的 CustomFunctions 创建一个单独的控制器和视图,以便它可以区分我的默认路线和我的 CustomFunctions,并在我的路线图中指定,如上所示。因此,当我转到 localhost\Viper 时,它将找到默认映射中指定的路由,而当我转到 localhost\Viper\CustomFunctions 时,它将找到到我的 .svc 文件的路由。 IgnoreRoute 基本上做到了这一点,因此您在调用页面时不必将文件扩展名放在 url 末尾。因此,我只指定 CustomFunctions,而不是 CustomFunctions.svc。执行此操作时,请确保将 System.ServiceModel.Activation 程序集和 using 语句添加到项目中。
感谢大家的帮助。希望这能帮助其他一些可怜的迷失的灵魂。