I have created WCF Restfull services , But when I'm Calling it from JS then it always saying Respurce is Not found. this is y employee class

namespace WcfRestMVC.Models
{
    [DataContract]
    public class Employee
    {
        [Key]
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string FirstName { get; set; }
        [DataMember]
        public string LastName { get; set; }

        [DataMember]
        public string Title { get; set; }
    }
}

ServiceInterface

namespace WcfRestMVC
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IEmployeeService" in both code and config file together.
    [ServiceContract]
    public interface IEmployeeService
    {
        [OperationContract]
        [WebGet(UriTemplate = "Employees", ResponseFormat = WebMessageFormat.Json)]
        Employee[] GetAllEmployee();

        [OperationContract]
        [WebGet(UriTemplate = "EmployeeById/{id}", ResponseFormat = WebMessageFormat.Json)]
        Employee GetEmployeeByID(string Id);
    }
}

My Services

namespace WcfRestMVC
{
    public class EmployeeService : IEmployeeService
    {
        public Employee[] GetAllEmployee()
        {
            using (DemoContext Dbobj = new DemoContext())
            {
                var getAllEmployee = Dbobj.eployees.ToList();
                return getAllEmployee.ToArray();
            }
        }


        public Employee GetEmployeeByID(string Id)
        {
            using (DemoContext Dbobj = new DemoContext())
            {
                var GetEmployeeById = Dbobj.eployees.FirstOrDefault(m => m.Id == Convert.ToInt32(Id));
                return GetEmployeeById;
            }
        }
    }
}

My web.config file as

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WcfRestMVC.EmployeeService">
        <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="WcfRestMVC.IEmployeeService" />
      </service>
    </services>
  </system.serviceModel>

I'm calling it from JS

$.ajax({
        type: "GET",
        url: "http://localhost:61716/EmployeeService.svc/Employees",
        contentType: "json",
        dataType: "json",
        success: function (data) {
            var d = data;
        },
        error: function (xhr) {
        var s=xhr;
        }
    });

also when paste this url in my browser

http://localhost:61716/EmployeeService.svc/Employees

It says The resource cannot be found.. I think something wrong in my web.config file. Can you please help me.

Related posts

Recent Viewed