重新映射WebService HttpHandler时出现奇怪的“文件'/DefaultWsdlHelpGenerator.aspx'不存在”错误

时间:2011-08-15 16:24:12

标签: asp.net webforms

我有动态CMS驱动(自定义滚动,我知道,轮子等,但不是我的决定!)网站,它使用HttpModule来引导内容。我发现.asmx资源不起作用。经过调查,我发现这是因为我基本上通过将请求从整个管道中取出来覆盖了处理程序。

所以我现在正在检测资源是否存在并且是.asmx文件,并进行相应的处理。我认为使用WebServiceHandlerFactory创建WebServiceHandler然后重新映射它。

这适用于?wsdl查询字符串,但是请求URI本身并且你得到(在星号表示的点):

  

System.InvalidOperationException未被用户代码
处理   消息=无法处理请求。   [剪断]      的InnerException:       System.InvalidOperationException          消息=无法处理请求。          来源= System.Web.Services          InnerException:System.Web.HttpException               Message =文件'/DefaultWsdlHelpGenerator.aspx'没有   存在。

注意最终的InnerException。此thread似乎表明.NET Framework安装已损坏,但该文件存在于4.0 Config文件夹中。我怀疑我的错误。我是否正确地重新映射?

public class xxxVirtualContentHttpModule : xxxHttpModule
{
        protected override void OnBeginRequest(IxxxContextProvider cmsContext, HttpContext httpContext)
        {
            string resolvePath = httpContext.Request.Url.AbsolutePath;

            // is path a physical file?
            IRootPathResolver rootPathResolver=new HttpServerRootPathResolver(httpContext.Server);
            string serverPath = rootPathResolver.ResolveRoot("~" + resolvePath);

            if (File.Exists(serverPath))
            {
                if (Path.GetExtension(serverPath).Equals(".asmx", StringComparison.CurrentCultureIgnoreCase))
                {
                    WebServiceHandlerFactory webServiceHandlerFactory = new WebServiceHandlerFactory();
                    IHttpHandler webServiceHttpHandler = webServiceHandlerFactory.GetHandler(httpContext, "Get", resolvePath, serverPath); // *****

                    httpContext.RemapHandler(webServiceHttpHandler);
                }
            }

        }

更新

我已删除对HttpModules的所有引用,但仍会出现此问题,这意味着它与系统的CMS部分无关。

1 个答案:

答案 0 :(得分:2)

解决了它。

似乎有一个新配置添加到web.config:

<system.web>
    <webServices>
        <wsdlHelpGenerator href="DefaultWsdlHelpGenerator.aspx" />
    </webServices>
</system.web>

删除了这一切,一切正常。