webservice    [WebService(Namespace = "http://test")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class Equipment : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string GetOperatorDefaultEquipCode(string operatorNum)
        {
            return "a";
        }web.config<httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>
    <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
 
    </httpHandlers>
jquery js$('#test').blur(function(){
 $.ajax({
     type: "POST",
     url: '/WebService/Equipment.asmx/GetOperatorDefaultEquipCode',
     cache: false,
     contentType: "application/json; charset=utf-8",
     data: "{operatorNum:'001'}",
     dataType: "json",
     success: function (data, status) {
         if (data.d) {
             ...
         }
     },
     error: function (XMLHttpRequest, textStatus, errorThrown) {
         debugger;
         
     }
 });
});
执行报错, error function中XMLHttpRequest的信息如下:<html>
    <head>
        <title>未能执行 URL。</title>
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .er {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
    </head>    <body bgcolor="white">            <span><H1>“/JMES”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1>            <h2> <i>未能执行 URL。</i> </h2></span>            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">            <b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。            <br><br>            <b> 异常详细信息: </b>System.Web.HttpException: 未能执行 URL。<br><br>            <b>源错误:</b> <br><br>            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code>                  </td>
               </tr>
            </table>            <br>            <b>堆栈跟踪:</b> <br><br>            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>[HttpException (0x80004005): 未能执行 URL。]
   System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.BeginExecuteUrl(String url, String method, String childHeaders, Boolean sendHeaders, Boolean addUserIndo, IntPtr token, String name, String authType, Byte[] entity, AsyncCallback cb, Object state) +2447593
   System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride, NameValueCollection requestHeaders, AsyncCallback cb, Object state) +417
   System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +192
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8968404
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +184
</pre></code>                  </td>
               </tr>
            </table>            <br>            <hr width=100% size=1 color=silver>            <b>版本信息:</b>&nbsp;Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.272            </font>    </body>
</html>
<!-- 
[HttpException]: 未能执行 URL。
   在 System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.BeginExecuteUrl(String url, String method, String childHeaders, Boolean sendHeaders, Boolean addUserIndo, IntPtr token, String name, String authType, Byte[] entity, AsyncCallback cb, Object state)
   在 System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride, NameValueCollection requestHeaders, AsyncCallback cb, Object state)
   在 System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
   在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->
以前项目都这样用,应该是OK的,这个项目中 这里就会报 未能执行 URL。
服务器.netFramework 4.0 IIS7

解决方案 »

  1.   

    而且比较奇怪的是,先通过localhost的webservice测试页面调用服务 一切OK。
    如果通过JQuery调用,报错之后,再通过localhost的webservice测试页面调用服务 就会报同样的错误我怀疑是 “/WebService/Equipment.asmx/GetOperatorDefaultEquipCode”的路径格式 ISAPI路由错误?
      

  2.   

    参考
    http://bbs.csdn.net/topics/360193668
      

  3.   

    个人认为是
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />       <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
    这两个版本太低的原因
      

  4.   

    还有iis7.0以上版本还要多配置这里
      

  5.   

      <system.webServer>    <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true">
          <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
          <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </modules>
        <handlers>
          <remove name="WebServiceHandlerFactory-Integrated"/>
          <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </handlers>
      </system.webServer>
      

  6.   

    本地开发环境下 通过VS的虚拟服务器都是好的,应该还是出在IIS7上。
    我本地并未使用MVC,而是传统的ASP.NET WebForm
     
      

  7.   

    谢谢这个大哥~我又发现一个奇怪的情况。。
    这个通过Jq调用WebService的页面是在iframe中的。但都是同一个webApp下,不存在跨域问题。
    如果我重启IIS后,将该页面单独运行,不放在iframe中,则一切OK。
    如果在iframe下调用,会发生上述异常;并且此时,再脱离iframe调用也会发生异常(已清理过IE缓存,应该不是IE缓存)。
      

  8.   


    那你是怎么调用的?之前缓存没清干净,刚又试了几次,没一次请求清一次缓存,明确了问题:
    1.同一个页面,如果在iframe下,页面中调用webservice的jquery ajax就会报错“未能执行URL”。
    2.如果不在iframe下直接访问该页面,则页面中调用webservice的jquery ajax正常获得结果。
      

  9.   

    想不明白,为什么用jquery ajax了还要用iframe来调用呢?
      

  10.   

    是这样的,系统布局是用iframe来布局的,分为上、左、中三块,左边是菜单,中间菜单对应的模块页面,这个页面是嵌入在中间的一块。刚才又深入测试了一下,发现之所以iframe中不行,是因为我都是从登陆->系统主页->点击模块->然后测试该页面的。
    而脱离iframe之所以行,是因为,我没有登陆系统,就直接打了该页面的url。如果纯粹在iframe中运行该页面,我试了是ok的,那应该就每个请求的Application_AuthenticateRequest中的问题了,我看了 Application_AuthenticateRequest中貌似有对cookie的相关操作。
    看来我要去深入研究下,晕死了。。谢谢楼上大哥的帮助
      

  11.   

    有啊 应该不是缓存的关系,貌似是在每个请求解析FormsAuthenticationTicket时有什么问题。之前已经换成不用webservice来做ajax了,也已经好了,但是总觉得心里不爽,想找找究竟是什么问题导致ScriptService出问题。
      

  12.   

    我先去用fiddler查下请求内容有什么线索
      

  13.   


    有没有试过,把IE浏览器关闭掉,重新打开呢?
    找到问题了... Global.asax中protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if (Request.IsAuthenticated)
        {
            string username = Context.User.Identity.Name;
            IApplicationContext ctx = ContextRegistry.GetContext();
            IAuthenticationService authenticationService = (IAuthenticationService)ctx["Portal.IAuthenticationService"];
            IPrincipal principal = authenticationService.CreateAuthenticatePrincipal(username);
            Context.User = principal; //设置当前用户的认证凭证
        }
    }通过js调用的webservice,在AuthenticateRequest的时候无法从IOC容器中获取对象,用的是Spring.net。真是神奇。改成下面这样就可以了...只是这样的话asmx中就不能获取到当前用户的认证信息了private static readonly string[] filterExtension = new string[] { ".asmx" };
    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if (Request.IsAuthenticated && !filterExtension.Contains(Request.CurrentExecutionFilePathExtension))    //过滤特定请求
        {
            string username = Context.User.Identity.Name;
            IApplicationContext ctx = ContextRegistry.GetContext();
            IAuthenticationService authenticationService = (IAuthenticationService)ctx["Portal.IAuthenticationService"];
            IPrincipal principal = authenticationService.CreateAuthenticatePrincipal(username);
            Context.User = principal; //设置当前用户的认证凭证
        }
    }