The RESTful WCF service returns "Resource not found". error

I have a RESTful service that is not working. When I enter the URI in the address bar, I get this error:

Resource is not found.

Description: HTTP 404. The resource you are looking for (or its dependencies) may have been deleted, its name changed or temporarily unavailable. Review the following URL and make sure it is spelled correctly.

Requested URL: /VirtualRUS/Service1.svc/

I can’t say why it doesn’t work. I compared my code and web.config with a working example, and I cannot find any differences.

EDIT: Also, I can use the service just fine if I use the link to the service. It just doesn't work if I go to the URI or, more importantly, when I try to do a WebRequest .

Does anyone know why this will not work?

Service1.cs:

 [ServiceContract] public interface IService1 { [OperationContract] [WebGet(UriTemplate = "/")] string Test(); } 

Service1.svc.cs:

 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class Service1 : IService1 { public string Test() { return "It works!!"; } } 

Web.Config:

 <?xml version="1.0" ?> <configuration> <configSections> <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /> <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> </sectionGroup> </sectionGroup> </sectionGroup> </configSections> <appSettings></appSettings> <connectionStrings> <add name="ResearchLibrary" connectionString="Server=XXXXXX" ; Initial Catalog=ResearchLibrary; user id=XXX; password=XXX " /> </connectionStrings> <system.web> <compilation debug="true "> <assemblies> <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089 "/> <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> </assemblies> </compilation> <authentication mode="Windows "/> <pages> <controls> <add tagPrefix="asp " namespace="System.Web.UI " assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> </controls> </pages> <httpHandlers> <remove verb="* " path="*.asmx "/> <add verb="* " path="*.asmx " validate="false " type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> <add verb="* " path="*_AppService.axd " validate="false " type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> <add verb="GET,HEAD " path="ScriptResource.axd " type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " validate="false "/> </httpHandlers> <httpModules> <add name="ScriptModule " type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> </httpModules> <httpRuntime maxRequestLength="65536 "/> </system.web> <system.codedom> <compilers> <compiler language="c#;cs;csharp " extension=".cs " warningLevel="4 " type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 "> <providerOption name="CompilerVersion " value="v3.5 "/> <providerOption name="WarnAsError " value="false "/> </compiler> </compilers> </system.codedom> <system.web.extensions> <scripting> <webServices> </webServices> </scripting> </system.web.extensions> <system.webServer> <validation validateIntegratedModeConfiguration="false "/> <modules> <add name="ScriptModule " preCondition="integratedMode " type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> </modules> <handlers> <remove name="WebServiceHandlerFactory-Integrated "/> <add name="ScriptHandlerFactory " verb="* " path="*.asmx " preCondition="integratedMode " type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> <add name="ScriptHandlerFactoryAppServices " verb="* " path="*_AppService.axd " preCondition="integratedMode " type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> <add name="ScriptResource " preCondition="integratedMode " verb="GET,HEAD " path="ScriptResource.axd " type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 "/> </handlers> </system.webServer> <system.serviceModel> <services> <service name="ResearchUploadService.Service1 " behaviorConfiguration="ResearchUploadService.Service1Behavior "> <!-- Service Endpoints --> <endpoint address="customBinding " binding="customBinding " bindingConfiguration="basicConfig " contract="ResearchUploadService.IService1 "/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ResearchUploadService.Service1Behavior "> <serviceMetadata httpGetEnabled="true "/> < <serviceDebug includeExceptionDetailInFaults="true "/> </behavior> </serviceBehaviors> </behaviors> <bindings> <customBinding> <binding name="basicConfig "> <binaryMessageEncoding/> <httpTransport transferMode="Streamed " maxReceivedMessageSize="67108864 "/> </binding> </customBinding> </bindings> </system.serviceModel> </configuration> 
+4
source share
1 answer

The endpoint is not a REST endpoint; it is a “normal” SOAP (binary encoding / HTTP transport) endpoint. REST endpoints are defined using specific binding (webHttpBinding) and behavior (webHttp). In addition, the Add Service link does not work for REST endpoints, which also indicates that if it works for you, then you are not using a REST endpoint.

To change the endpoint to RESTful, you can change the web.config file as shown below (it actually adds a REST endpoint in addition to the SOAP that you already have).

 <system.serviceModel> <services> <service name="ResearchUploadService.Service1" behaviorConfiguration="ResearchUploadService.Service1Behavior"> <!-- Service Endpoints --> <endpoint address="customBinding" binding="customBinding" bindingConfiguration="basicConfig" contract="ResearchUploadService.IService1"/> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="REST" contract="ResearchUploadService.IService1"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ResearchUploadService.Service1Behavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="REST"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <bindings> <customBinding> <binding name="basicConfig"> <binaryMessageEncoding/> <httpTransport transferMode="Streamed" maxReceivedMessageSize="67108864"/> </binding> </customBinding> </bindings> </system.serviceModel> 
+10
source

All Articles