【问题标题】:Asp.Net Ajax WebService and Internal Error 500Asp.Net Ajax WebService 和内部错误 500
【发布时间】:2011-01-31 09:08:28
【问题描述】:

我可以使用以下 URL 直接将 webservie 调用到浏览器,它会返回我想要的所有内容:

http://localhost:64438/MySearchAutoComplete.asmx/GetCompletionList

当我像这样将它添加到 Default.aspx 页面的 autocompleteexetender 时:

<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" 
                  TargetControlID="TextBox1" 
                  runat="server" 
                  ServiceMethod="GetCompletionList" 
                  ServicePath="http://localhost:64438/MySearchAutoComplete.asmx" 
                  CompletionSetCount="12"
                  MinimumPrefixLength="1" />

页面加载,我有一个文本框,但每次在文本框中添加击键时都会出现错误 500。我在 FireFox FireBug 中看到了错误。

http://localhost:62702/   --->This is the webpage that load fine 

--> 这是错误

有什么想法吗?我注意到我需要附加进程来调试 web 服务,我可能也会做错什么?

编辑(事件查看器)

如果我转到我机器的事件查看器。我可以看到:

Exception information: 
    Exception type: InvalidOperationException 
    Exception message: Request format is unrecognized for URL unexpectedly ending in '/GetCompletionList'. 


    Thread information: 
    Thread ID: 8 
    Thread account name: MTL\daok 
    Is impersonating: False 
    Stack trace:    at     System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
   at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我还必须先启动 webservice 项目,然后停止它并启动 webproject 才能同时拥有两者。网络服务仍然有效(我可以直接触发它http://localhost:64438/MySearchAutoComplete.asmx?op=GetCompletionList)但在网页上我仍然有错误 500。

编辑 2 (Web.config)

添加到webservice项目web.config:

  <webServices>
    <protocols>
      <add   name="HttpGet"/>
      <add   name="HttpPost"/>
    </protocols>
  </webServices>

还没有解决问题。

编辑 3(直接调用)

在 Page_Load() 中调用 WebService 中的相同方法效果很好:

     string[] stuffs;
     stuffs = proxy.GetCompletionList("1", 10);
     MyList.DataSource = stuffs;
     MyList.DataBind();

但它不适用于 AutoCompleteExtender...

【问题讨论】:

    标签: c# asp.net asp.net-ajax web-services


    【解决方案1】:

    在网络服务器(即您的本地计算机)上的事件日志中,它应该提供更详细的错误消息。

    我认为将此添加到您的 web.config 中

    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    

    【讨论】:

    • 一切仍在 Visual Studio 中。它尚未部署。
    • 好吧,这就是我所看到的:InvalidOperationException 请求格式无法识别,因为 URL 意外以“/GetCompletionList”结尾。 localhost:64438/MySearchAutoComplete.asmx/GetCompletionList /MySearchAutoComplete.asmx/GetCompletionList
    • 我也有同样的问题。这可能是引用网络服务的方式吗?例如,我必须先将 webservice 设置为启动项目,然后停止并将启动项目设置为 web 项目。这样做可确保 Web 服务正在运行。在我的记忆中,过去,我只需要启动 web 服务,一切就都好了......
    • 您是否尝试按照该线程将 内容添加到 web.config?
    • WebService 的 web.config 非常空白。来自网页的那个具有 Asp.Net Ajax 所需的所有“正常”标签。
    【解决方案2】:

    只需确保您取消注释位于 Web 服务类页面顶部 WebServiceBinding 下方的 [System.Web.Script.Services.ScriptService]

    这应该可以解决。 如果仍然存在,请检查您的SitePath 的 URL,确保它正确地植根于 Web 服务的位置,方法是在 URL 前添加“~”,如下所示:

    SitePath="~/Webservice.asmx"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 2012-04-25
      • 1970-01-01
      相关资源
      最近更新 更多