37

I am get the following error while running web service in 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

Does anyone know why I am seeing this error and if there is any way to fix it?

2

3 Answers 3

91

Since HTTP GET and HTTP POST are disabled by default try adding the following to your config file:

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>
6
  • 7
    How come they are both disabled? What is enabled by default?
    – Elad Benda
    Oct 29, 2011 at 21:41
  • wouldn't using queryString have solved the problem? meaning ?op=GetMailsInfo
    – Elad Benda
    Oct 29, 2011 at 21:42
  • For asp.net1.1 <webServices> <protocols> <add name="HttpSoap" /> <add name="HttpPost" /> <add name="HttpGet" /> </protocols> </webServices> Jan 7, 2014 at 16:46
  • Elad Brenda, some of the older style asmx stuff uses query strings like blahblah.asmx/dosomestuff by default. Another reason to upgrade to WCF I guess.
    – infocyde
    Feb 3, 2015 at 23:00
  • i can send request but not able to receive response from server , i am retiring xml from server . is there any more configuration needed . Jun 2, 2015 at 12:28
5

I've got the same issue. To solve it add [ScriptService] to your service

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

        }
    }
}
3

Just out of interest (- in the case of accessing the web-service via AJAX); I've found that if a 'content-type' header is not passed (- even if it's a local/"HttpPostLocalhost" request), then the issue occurs, so I pass the header myself (- e.g. via jQuery's '$.ajax()' method rather than without via jQuery's '$.getJSON()' method), instead of resorting to this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy