如何修复IIS中运行的Web服务中的"请求格式无法识别URL ..."错误?

37 asp.net web-services

在IIS中运行Web服务时出现以下错误:

'/ Inbox Sevice'应用程序中的服务器错误.对于意外以"/ GetMailsInfo"结尾的URL,无法识别请求格式.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.

异常详细信息:System.InvalidOperationException:对于意外以'/ GetMailsInfo'结尾的URL无法识别请求格式.

来源错误:

在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.

堆栈跟踪:

[InvalidOperationException:对于意外以'/ GetMailsInfo'结尾的URL无法识别请求格式.]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type,HttpContext context,HttpRequest request,HttpResponse response)+490982 System.Web.Services. Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context,String verb,String url,String filePath)+104
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context,String requestType,String url,String pathTranslated)+127
System.Web.HttpApplication.MapHttpHandler(HttpContext context,String requestType,VirtualPath path,String pathTranslated,Boolean useAppConfig)+175 System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+120 System.Web.HttpApplication. ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+155

版本信息:Microsoft .NET Framework版本:2.0.50727.42; ASP.NET版本:2.0.50727.42

有谁知道为什么我看到这个错误,如果有任何方法可以解决它?

And*_*are 89

由于默认情况下禁用 HTTP GET和HTTP POST ,请尝试将以下内容添加到配置文件中:

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

  • 怎么他们都被禁用了?什么是默认启用? (6认同)

小智 5

我有同样的问题.要解决此问题,请将[ScriptService]添加到您的服务中

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Script.Services;
    using System.Web.Services;

    namespace DemosAjaxcontroltoolkit
    {
        /// <summary>
        /// Summary description for WebService
        /// </summary>
        [ScriptService] 
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class WebService : System.Web.Services.WebService
        {

            [System.Web.Script.Services.ScriptMethod()]
            [WebMethod]

            public string[] GetWords(string prefixText, int count)
            {
                List<string> words = new List<string>();
                words.Add("Apple");
                words.Add("Appertizer");
                words.Add("Apple tree");
                words.Add("Apple Cider");
                words.Add("Afternoon");
                words.Add("Morning");
                words.Add("Breakfeast");
                words.Add("Lunch");
                words.Add("Spider");
                words.Add("Morning");
                words.Add("Day");
                words.Add("Travel");
                words.Add("Night");
                words.Add("Car");
                words.Add("Bikes");
                words.Add("Love");
                words.Add("Good");

                //return words.Where(w => w.StartsWith(prefixText)).Take(count).ToList();

                //List<string> returnedList = words.Where(w => w.StartsWith(prefixText)).Take(count).ToList();
                return words.Where(w => w.ToUpper().StartsWith(prefixText.ToUpper())).ToArray();
            }

        }
    }
}
Run Code Online (Sandbox Code Playgroud)