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'.
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
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
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()?
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:
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'.
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:
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.
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
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
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
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:
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)
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.
Jazzcatone
Member
254 Points
84 Posts
Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 07, 2006 04:18 AM|LINK
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 Setda.Fill(ds,
"employees"); return ds;}
}
TwasBrillig
Member
285 Points
109 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 07, 2006 08:33 AM|LINK
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()?
Jazzcatone
Member
254 Points
84 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 07, 2006 01:31 PM|LINK
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.
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
TwasBrillig
Member
285 Points
109 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 07, 2006 05:34 PM|LINK
The code block:
{
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:string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
}
{
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.
Jazzcatone
Member
254 Points
84 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 07, 2006 06:40 PM|LINK
TwasBrillig
Member
285 Points
109 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 07, 2006 08:21 PM|LINK
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
TwasBrillig
Member
285 Points
109 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 07, 2006 08:28 PM|LINK
To enable all the debugging goodies, be sure the following is set:
Visual Web Developer Menu
Website
Start Options
Debuggers
SELECT: ASP.NET
Shannon
Ben74
Member
30 Points
7 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 10, 2006 12:04 AM|LINK
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: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.
TwasBrillig
Member
285 Points
109 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 10, 2006 01:07 PM|LINK
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.
Ben74
Member
30 Points
7 Posts
Re: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
May 10, 2006 06:45 PM|LINK