Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

Rate It (1)

Last post 05-14-2008 2:30 PM by jfaigan. 14 replies.

Sort Posts:

  • Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-07-2006, 12:18 AM
    • Loading...
    • Jazzcatone
    • Joined on 06-14-2005, 7:49 PM
    • Posts 64

    Hello and thank you for taking a moment. Let me say that I am brand new to Web Services. Please forgive my ignorance on some of these issues. I have created a web service in VS 2005.  When I go to run the code my web service description (test) pages come up fine.( These are the pages that give a description of the web service along with the available methods) I click on the name of one of the methods and come to the the page that lets me invoke that method.

    When I click the 'invoke' button I receive a page not displayed error and when I refresh VS then throws me the following Error:

    Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    indeed the url of this page is http://localhost:1223/WebSite12/Service.asmx/GetEmployees

    I just don't know what to do in order to get the method to give me the information I want. The book I am borrowing code from says it should work. Below is my asmx and codebehind. Any help you could provide would be greatly appreciated.- Jason

    ---------------------------------------------------------------------------------------------

    Service.asmx ( this is set as my start page of my project)

    <%

    @ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="EmployeesService" %>

    ------------------------------------------------------------------------------------------------------------

    App_Code\Service.cs (CodeBehind)]

    using

    System;

    using

    System.Web;

    using

    System.Collections;

    using

    System.Web.Services;

    using

    System.Web.Services.Protocols;

    using

    System.Data.SqlClient;

    using

    System.Data;

     

    ///

    <summary>

    ///

    Summary description for WebService

    ///

    </summary>

    ///

     

     

    [

    WebService(Name = "Employees Service", Description = "Retrieve the NorthWind Employees")]

    public

    class EmployeesService : System.Web.Services.WebService

    {

    private string connectionString;

    public EmployeesService()

    {

    string connectionString =

    System.Web.Configuration.

    WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;

    }

    [

    WebMethod(Description = "Returns the total number of Employees.")]

    public int GetEmployeesCount()

    {

    SqlConnection con = new SqlConnection(connectionString);

    string sql = "Select Count(*) From Employees";

    SqlCommand cmd = new SqlCommand(sql, con);

    //Open the connection and Get the value.

    con.Open();

    int numEmployees = -1;

    try

    {

    numEmployees = (

    int)cmd.ExecuteScalar();

    }

    finally

    {

    con.Close();

    }

    return numEmployees;

    }

    [

    WebMethod(Description = "Return full list of employees.")]

    public DataSet GetEmployees()

    {

    // Create the command and the connection.

    string sql = "SELECT EmployeeID, LastName,FirstName, Title, " +

    "TitleOfCourtesy,HomePhone FROM Employees";

    SqlConnection con = new SqlConnection(connectionString);

    SqlDataAdapter da = new SqlDataAdapter(sql, con);

    DataSet ds = new DataSet();

    //Fill Data Set

    da.Fill(ds,

    "employees");

    return ds;

    }

     

     

    }

     

     

     

  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-07-2006, 4:33 AM
    Note that the string you set in the constructor is not visible outside the constructor.
    Other than that, the code works fine on ASP.NET 2.0

    The page returns XML at the link you mentioned, but to work properly it must be accompanied by form data and web service headers.  You should expect the URL error if you just paste in the asmx/GetEmployees link.

    I assume "page not displayed error" was a typo?  Tell us more about the initial error.

    Does Invoke work properly for GetEmployeesCount()?
  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-07-2006, 9:31 AM
    • Loading...
    • Jazzcatone
    • Joined on 06-14-2005, 7:49 PM
    • Posts 64

    Hello and thanks again. I am assuming the strings you are referring to are my SQL expressions. I am not 100% what you mean by "visible'. Again ... I apologize for my ignorance. Do you mean that the expreesion can only be used when the particular method is called?

    You said to work properly it must be accompanied by form data and web service headers.Not really sure what this means completely. Do you mean that I have to create an aspx with a form on it? I don't really know what Web Service Headers are?

    One thing I didn't mention is that on my Invoke page for GetEmployees(). There is a message underneath my Invoke button that says this message:

    ----------------------------------------------------------------------------------------------------- SOAP 1.1

    The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

    POST /WebSite12/Service.asmx HTTP/1.1
    Host: localhost
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://tempuri.org/GetEmployees"
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <GetEmployees xmlns="http://tempuri.org/" />
      </soap:Body>
    </soap:Envelope>
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <GetEmployeesResponse xmlns="http://tempuri.org/">
          <GetEmployeesResult>
            <xsd:schema>schema</xsd:schema>xml</GetEmployeesResult>
        </GetEmployeesResponse>
      </soap:Body>
    </soap:Envelope>

    SOAP 1.2

    The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.

    POST /WebSite12/Service.asmx HTTP/1.1
    Host: localhost
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <GetEmployees xmlns="http://tempuri.org/" />
      </soap12:Body>
    </soap12:Envelope>
    HTTP/1.1 200 OK
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <GetEmployeesResponse xmlns="http://tempuri.org/">
          <GetEmployeesResult>
            <xsd:schema>schema</xsd:schema>xml</GetEmployeesResult>
        </GetEmployeesResponse>
      </soap12:Body>
    </soap12:Envelope>

    HTTP POST

    The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.

    POST /WebSite12/Service.asmx/GetEmployees HTTP/1.1
    Host: localhost
    Content-Type: application/x-www-form-urlencoded
    Content-Length: length
    
    
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <DataSet xmlns="http://tempuri.org/">
      <schema xmlns="http://www.w3.org/2001/XMLSchema">schema</schema>xml</DataSet>
    -------------------------------------------------------------
    I don't really know if that  was helpful or not....

    When I click my invoke button I get a 'Page cannot be displayed' error. ( HTTP 500 - Internal server error Internet Explorer Please try the following:...One of the options listed is to refresh.) I refresh this page and this when I get my Url Error.

    -----------------------------------------------------------------------------------------------------

    Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    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 '/GetEmployees'.

    -----------------------------------------------------------------------------------------------------

    Any help would be greatly appreciated and I thank you for your time and patience. - Jason

  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-07-2006, 1:34 PM
    "not visible"
    The code block:

    {
    string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
    }

    Basically creates a NEW variable named connectionString inside those brackets (called "scope").  While "in scope", it hides the one you are actually trying to set.  Then, when you leave the code block, it is gone.  What you probably intended was:

    {
    connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
    }


    Page cannot be displayed... Internal server error

    Yes, probably just indicates that the variable scope issue we've already discussed generated an exception, regarding which the server knows more about but isn't telling.  It's your server, don't take that crap.  Turn on debugging for the project.  Also turn on in-client-browser error output for the web site.  The place to set these two items varies depending on the version you are using.  Turn it all back off before you put anything on the public 'net.



    GetEmployeesCount()

    You still didn't tell us if this other Invoke works.  I suspect it doesn't.

  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-07-2006, 2:40 PM
    • Loading...
    • Jazzcatone
    • Joined on 06-14-2005, 7:49 PM
    • Posts 64
    Well... I know debugging is usually set in the Web.Config. and I have a <compilation debug="true"/> in the Web.Config. I must admit I don't know how to turn on in-client-browser error output for the web site.I am using ASP.NET 2.0 with Visual Studio 2005. I am using Internet Explorer 6.0 as my browser. And yes you are correct,  GetEmployeesCount() does not work, I get the same URL error when I try to invoke the Method. I took the data type string off of my ConnectionString to eliminate the scope problem but to no avail.  Thanks again- Jason 
  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-07-2006, 4:21 PM
    My Computer:Manage:Services and Applications:Internet Information Services:<your website>:Tab(ASP.NET):Button(Edit Configuration...):Tab(Custom Errors)

    SELECT: Remote Only (or Off, if you are working remotely)

    However, it actually sounds like you might be seeing Internet Explorer covering up the error.  It sounds familiar, although I primarily use Firefox so I don't know offhand.  Go to IE:Tools:Internet Options:Advanced:Browsing

    DESELECT: Show friendly HTTP error messages


    Shannon
  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-07-2006, 4:28 PM
    Also, if you are testing the app locally, use "F5" to start debugging.  Try setting a breakpoint in your application to be sure it is working.  Focus should switch back to Visual Studio when the breakpoint is hit.

    To enable all the debugging goodies, be sure the following is set:

    Visual Web Developer Menu
        Website
            Start Options
                Debuggers
                    SELECT: ASP.NET


    Shannon
  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-09-2006, 8:04 PM
    • Loading...
    • Ben74
    • Joined on 02-10-2005, 1:12 PM
    • Posts 6
    i am having a similar problem. i have a web service that works fine when i call it from the local machine. however, from other machines, i get the same error as in the topic title. i am calling the web service via ajax (not atlas). when i run the ajax code in the browser on my dev machine, it works great. however, from any other machine, the web service returns a 500 HTTP code, and i get the following in the windows application event log:

    Event code: 3005
    Event message: An unhandled exception has occurred.
    Event time: 5/9/2006 4:47:53 PM
    Event time (UTC): 5/9/2006 11:47:53 PM
    Event ID: 9439fbe4d34a45a8823c2e860a466c7b
    Event sequence: 311
    Event occurrence: 6
    Event detail code: 0
     
    Application information:
        Application domain: /LM/W3SVC/1/Root/porders-1-127916911407506700
        Trust level: Full
        Application Virtual Path: /porders
        Application Path: c:\inetpub\wwwroot\porders\
        Machine name: XXXXX
     
    Process information:
        Process ID: 4424
        Process name: w3wp.exe
        Account name: NT AUTHORITY\NETWORK SERVICE
     
    Exception information:
        Exception type: InvalidOperationException
        Exception message: Request format is unrecognized for URL unexpectedly ending in '/QueryVendp'.
     
    Request information:
        Request URL: http://XXXXX/porders/WebSvc.asmx/QueryVendp
        Request path: /porders/WebSvc.asmx/QueryVendp
        User host address: XXXXX
        User: XXXXX
        Is authenticated: True
        Authentication Type: Negotiate
        Thread account name: NT AUTHORITY\NETWORK SERVICE
     
    Thread information:
        Thread ID: 1
        Thread account name: NT AUTHORITY\NETWORK SERVICE
        Is impersonating: True
        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)
     
     
    Custom event details:
    here is the code for the web method i'm calling:

     
    [WebMethod(CacheDuration=60)]
        public XmlDocument QueryVendp(int iCompanyCode, string sVendorCode)
        {
            XmlDocument oXML;
            oXML = new XmlDocument();
    
            try
            {
                oXML.LoadXml((string)SqlHelper.ExecuteScalar(Config.ConnStringOrders, "selectVendor4XML", iCompanyCode, sVendorCode));
            }
            catch (Exception err)
            {
                DataAccess.LogEvent("none", false, "WebSvc", "QueryVendp", "iCompanyCode = " + iCompanyCode.ToString() + ", sVendorCode = " + sVendorCode + "; " + err.Message);
            }
    
            return oXML;
        }
     here's the javascript that calls the web service:

     
    xmlhttp.open("POST", "WebSvc.asmx/QueryVendp?iCompanyCode=1&sVendorCode=99999", true);
     
    again, this all works great on the dev machine. it only fails when accessed remotely. is this some sort of permissions or config issue? thanks.
  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-10-2006, 9:07 AM
    Could be permissions, but I think, as was the main topic in the previous post, you first have to find out what the error is.

    If you are using Internet Explorer, turn off (on the machine you see the useless error on)
        Show friendly HTTP error messages
    In tools, options, advanced.


  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-10-2006, 2:45 PM
    • Loading...
    • Ben74
    • Joined on 02-10-2005, 1:12 PM
    • Posts 6
    the error message is right there in my post, from the event log. since it's being called via ajax, you don't see it in the browser.
  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-10-2006, 7:23 PM
    • Loading...
    • Ben74
    • Joined on 02-10-2005, 1:12 PM
    • Posts 6
    i found the solution. i put the following in my web.config


     
    <webServices>
    <protocols>
    <add name="HttpGet"/>
    <add name="HttpPost"/>
    </protocols>
    </webServices>
     
  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    05-10-2006, 11:47 PM
    oops, I think I replied to the wrong post the last time.  lots of people posting about error 500s.  you know, after you sign in you have to find the thread again.  Thanks for posting your solution.
  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    03-27-2008, 3:59 PM
    • Loading...
    • vt1991
    • Joined on 03-27-2008, 7:55 PM
    • Posts 2

    Ben74, thank you so much for posting this.  It is very easy to forget to add this in the web.config especially if you did not start the project as a webservice project. The error does not even give a clue that this is the issue.  I was pulling my hair out for a while with this error.  Adding the above lines to the web.config fixed the error for me.

  • Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.

    04-19-2008, 5:20 AM