Using this tutorial:
http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
I can get a Directory Listing to display when I run the app from VS 2010.
I can paste the URL that is displayed in the IE Browser that VS invokes (http://localhost:4841/) into an outside-of-VS instance of IE and see the same thing. However, if I append “/xml/123” or “/json/123” as shown in the tutorial, so that the URI is “http://localhost:4841/xml/123” or “http://localhost:4841/json/123”, I get:
*Server Error in ‘/’ Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /json/123/
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272*
If I append “RestServiceImpl.svc” to the URI, so that it is “http://localhost:4841/RestServiceImpl.svc” I get the “Service” page (“This is a Windows© Communication Foundation service. Metadata publishing for this service is currently disabled.”); but appending “/xml/123” or “/json/123” leads to the same 404.
The most pertinent code (taken straight from the 5-star tutorial) is:
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "xml/{id}")]
string XMLData(string id);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json/{id}")]
string JSONData(string id);
}
Okay, I solved the dilemma by replacing, in Web.config, this:
…with this:
(and the other place where “RestService” appears with “REST_JSON_POC”)
(“RestService” is what the tutorial had, but REST_JSON_POC is the name of my project)
But now I have another problem, for which I will create a new question (the “xml/123” now works fine, but “json/123” prompts to download a file, named “123” which has the expected string in it).