我正在尝试在Visual Studio中的C#中创建一个简单的REST服务。运行并导航到http://localhost:63735/Service1.svc/Tutorial时,出现以下一般错误:
当我刚浏览到http://localhost:63735时,它显示标准页面“ ASP> NET是一个免费的Web框架,用于使用HTML,CSS和JavaScript构建出色的网站。” 开发者控制台似乎没有提供任何进一步的信息。更改浏览器时不会更改。
我按照https://www.guru99.com/restful-web-services.html的教程构建了这个简单的REST服务。我想念什么?
Service1.svc.cs:
namespace WebApplication1
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
private static List<string> lst = new List<string>(new String[] {"Arrays","Queues","Stacks"});
[WebGet(UriTemplate="/Tutorial")] //GET at /Tutorial (for the following method)
public String GetAllTutorial()
{
int count = lst.Count;
String TutorialList = "";
for (int i = 0; i < count; i++)
TutorialList = TutorialList + lst[i] + ",";
return TutorialList;
}
[WebGet(UriTemplate = "/Tutorial/{Tutorialid}")]
public String GetTutorialbyID(String Tutorialid)
{
int pid;
Int32.TryParse(Tutorialid, out pid);
return lst[pid];
}
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json,UriTemplate = "/Tutorial", ResponseFormat = WebMessageFormat.Json, BodyStyle =WebMessageBodyStyle.Wrapped)]
public void AddTutorial(String str)
{
lst.Add(str);
}
[WebInvoke(Method = "DELETE", RequestFormat = WebMessageFormat.Json, UriTemplate = "/Tutorial/{Tutorialid}", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
public void DeleteTutorial(String Tutorialid)
{
int pid;
Int32.TryParse(Tutorialid, out pid);
lst.RemoveAt(pid);
}
}
}