Restful web service Endpoint not found
This is one of the best articles I found when I first started learning rest; I wish I was at work now I have the exact TimeService example but I just Googled and could not find the same code.
Tomorrow from work I will post a working example if you still need it.
atrljoe
I am Senior Level Developer who enjoys learning new things and helping people. I am especially interested in c# but have worked with many languages.
Updated on November 21, 2020Comments
-
atrljoe over 3 years
I am trying to build a basic REST web service that simply returns the current time and whenever I try to I get the following error whenever I try to call my service http://localhost:PORT/TimeService/CurrentTime:
Endpoint not found. Please see the service help page for constructing valid requests to the service.
What am I doing wrong? Below you can find all the code I am using. Thank You
Service1.cs
using System; using System.Collections.Generic; using System.Linq; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; using System.Text; namespace WcfRestService1 { [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class TimeService { [WebGet(UriTemplate = "CurrentTime")] public string CurrentTime() { return DateTime.Now.ToString(); } } }
Global.asax
using System; using System.ServiceModel.Activation; using System.Web; using System.Web.Routing; namespace WcfRestService1 { public class Global : HttpApplication { void Application_Start(object sender, EventArgs e) { RegisterRoutes(); } private static void RegisterRoutes() { RouteTable.Routes.Add(new ServiceRoute("TimeService", new WebServiceHostFactory(), typeof(TimeService))); } } }
web.config
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </modules> </system.webServer> <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <standardEndpoints> <webHttpEndpoint> <!-- Configure the WCF REST service base address via the global.asax.cs file and the default endpoint via the attributes on the <standardEndpoint> element below --> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> </webHttpEndpoint> </standardEndpoints> </system.serviceModel> </configuration>
-
atrljoe over 12 yearsThat would be very helpful if you could post that.