我有动态 CMS 驱动的(自定义滚动,我知道,轮子等,但不是我的决定!)站点,它使用 HttpModule 来引导内容。我发现 .asmx 资源无法正常工作。经过调查,我发现这是因为我基本上通过从整个管道中取出请求来覆盖处理程序。
所以我现在正在检测资源是否存在并且是 .asmx 文件,并进行相应的处理。我认为是使用 WebServiceHandlerFactory 创建一个 WebServiceHandler,然后重新映射它。
这对于 ?wsdl 查询字符串来说效果很好,但是询问 URI 本身,您会得到(在星号指示的点):
System.InvalidOperationException 未由用户代码处理
消息=处理请求失败。 [剪] 内部异常: 系统无效操作异常 消息=无法处理请求。 源=System.Web.Services 内部异常:System.Web.HttpException 消息=文件“/DefaultWsdlHelpGenerator.aspx”不 存在。
注意最后的 InnerException。此线程似乎表明 .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 部分无关。
解决了。
web.config 中似乎添加了新配置:
<system.web>
<webServices>
<wsdlHelpGenerator href="DefaultWsdlHelpGenerator.aspx" />
</webServices>
</system.web>
删除这个,一切正常。
此处不做解释;我也遇到同样的错误。
我的修复方法是在服务器上运行“iisreset”,然后重新加载页面,然后它就消失了。