2009-03-17 1 views
34

Я получаю следующее сообщение об ошибке при запуске веб-службы в IIS:Как исправить ошибку «Request format is unrecognized for URL ...» в веб-службе, работающей в IIS?

Server Error in '/Inbox Sevice' Application. Request format is unrecognized for URL unexpectedly ending in '/GetMailsInfo'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetMailsInfo'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetMailsInfo'.]
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

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

Кто-нибудь знает, почему я вижу эту ошибку, и если есть какой-нибудь способ это исправить?

+1

возможно дубликат [формат запроса нераспознан для URL неожиданно заканчивающийся в] (HTTP: //stackoverflow.com/questions/657313/request-format-is-unrecognized-for-url-unexpectedly-ending-in) –

+0

Чтобы сделать это проще для Google, немецкий перевод сообщения об ошибке читает «** Unbekanntes Anforderungsformat für eine URL, die unerwartet mit '/ _myMethodName' endet. ** ". –

ответ

86

Поскольку HTTP GET и POST HTTP являются disabled by default попробуйте добавить следующие строки в файл конфигурации:

<configuration> 
    <system.web> 
    <webServices> 
     <protocols> 
      <add name="HttpGet"/> 
      <add name="HttpPost"/> 
     </protocols> 
    </webServices> 
    </system.web> 
</configuration> 
+5

Почему они оба отключены? Что включено по умолчанию? –

+0

не использовал бы queryString, решив проблему? это означает? оп = GetMailsInfo –

+0

Для asp.net1.1 \t \t \t \t \t \t \t \t <добавить имя = "HttpSoap" /> \t \t \t \t <добавить имя = "HttpPost" /> \t \t \t \t <добавить имя = "HttpGet" /> \t \t \t \t \t \t \t \t \t

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(); 
      } 

     } 
    } 
} 
2

Просто из интереса (- в случае доступа к веб-сервиса с помощью AJAX); Я обнаружил, что если заголовок «content-type» не передается (даже если это локальный запрос «HttpPostLocalhost»), возникает проблема, поэтому я сам передаю заголовок (например, через jQuery «$ .ajax»() метод, а не без с помощью JQuery в '$ .getJSON()' метод), вместо того, чтобы прибегать к этому:

https://support.microsoft.com/en-us/kb/819267

Смежные вопросы