Emrah KONDUR
Emrah KONDUR

Reputation: 196

404 not found on WCF REST service

I'have configured REST on WCF service. I have an other project working like this and copied from to my project all config and things. But when I run it, rest method and /web page not found.

Web.config:

> <appSettings>
>     <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />   </appSettings>   <system.web>
>     <compilation debug="true" targetFramework="4.5" />
>     <httpRuntime targetFramework="4.5"/>   </system.web>   <system.serviceModel>
>     <services>
>       <service name="WcfRestTest.Service1">
>         <clear />
>         <endpoint behaviorConfiguration="RFEndPointBehavior" binding="webHttpBinding"
>           contract="WcfRestTest.IService1" listenUriMode="Explicit">
>         </endpoint>
>       </service>
>     </services>
>     <behaviors>
>       <endpointBehaviors>
>         <behavior name="RFEndPointBehavior"  >
>           <webHttp helpEnabled="true"/>
>         </behavior>
>       </endpointBehaviors>
>     </behaviors>
>     <protocolMapping>
>       <add binding="basicHttpsBinding" scheme="https" />
>     </protocolMapping>
>     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />   </system.serviceModel>  
> <system.webServer>
>     <modules runAllManagedModulesForAllRequests="true"/>
>     <directoryBrowse enabled="true"/>   

Service Class:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
    public List<Student> GetStudentDetails()
    {
        List<Student> stuList = new List<Student>();
        stuList.Add(new Student { ID = "1", Name = "Test" });
        return stuList;
    }
}

Service Contract:

[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebGet(UriTemplate = "Students", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        List<Student> GetStudentDetails();
    }

[DataContract]
public class Student
{
    [DataMember]
    public string ID { get; set; }
    [DataMember]
    public string Name { get; set; }
}

Upvotes: 0

Views: 207

Answers (1)

Abraham Qian
Abraham Qian

Reputation: 7522

I coped you code segments and found it works well. In my opinion, there is something wrong with the address you accessed.
For the WCF Rest service hosted in IIS, we are supposed to use the IIS base address and the UriTemplate property,

[WebGet(UriTemplate = "Students", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]

For example, here is a below site binding in IIS.
enter image description here
The service base address is http://MyIP:11000/service1.svc, and the operation should be routed by using http://MyIP:11000/service1.svc/Students.
One more thing must be noted is that the service usually has a relative address. Assumed that there is a below definition.

<endpoint address="myservice" binding="webHttpBinding" contract="WcfService3.IService1" listenUriMode="Explicit"></endpoint>

It should also be taken into account.
http://MyIP:11000/service1.svc/myservice/Students
Feel free to let me know if there is anything I can help with.

Updated

<system.serviceModel>
<services>
  <service name="WcfRestTest.Service1">
    <clear />
    <endpoint behaviorConfiguration="RFEndPointBehavior" binding="webHttpBinding"
      contract="WcfRestTest.IService1" listenUriMode="Explicit">
    </endpoint>
  <endpoint address="" binding="webHttpBinding" contract="WcfRestTest.IService1" behaviorConfiguration="RFEndPointBehavior" bindingConfiguration="mybinding"></endpoint>
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="mybinding">
      <security mode="Transport">
        <transport clientCredentialType="None"></transport>
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="RFEndPointBehavior"  >
      <webHttp helpEnabled="true"/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

Upvotes: 1

Related Questions