Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am stuck since severals hours on that problem and i need someone to point me out my mistake.

The VS2010 project is configured to run on the 2722 port with the Visual Studio Development Server.

When i try to browse this url :
http://localhost:2722/Web/EmployeeService.svc/GetEmployee/1

I get the following error :
Http 400 bad request.

And in the WCF log file :
The body of the message cannot be read because it is empty.

Thanks for your time!


Below, the files :

----------------------------
Interface :
Web/IEmployee.cs
----------------------------
C#
namespace WcfServices.Web
{
    [ServiceContract]
    interface IEmployee
    {
        [WebGet(UriTemplate = "GetEmployee/{id=1}")]
        [OperationContract]
        Employee GetEmployee(String id);
    }
}

----------------------------
The implementation :
Web/EmployeeService.cs
----------------------------
C#
namespace WcfServices.Web
{
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
    public class EmployeeService : IEmployee
    {
        private IList<Employee>_list = new List<Employee>();

        EmployeeService()
        {
            _list.Add(new Employee() { Id = 1, FirstName = "Joe", LastName = "Dalton"});
            _list.Add(new Employee() { Id = 2, FirstName = "Luke", LastName = "Lucky" });
            _list.Add(new Employee() { Id = 3, FirstName = "Ma", LastName = "Dalton" });
            _list.Add(new Employee() { Id = 4, FirstName = "Rantanplan", LastName = "Unknow" });
        }

        Employee IEmployee.GetEmployee(String id)
        {
            int __id;
            if (int.TryParse(id, out __id))
            {
                return _list[__id];    
            }
            return null;
        }
    }
}


--------------------------------------
The data structure :
Data/Employee.cs
--------------------------------------
C#
namespace WcfServices.Data
{
    [DataContract]
    public class Employee
    {
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string LastName { get; set; }
        [DataMember]
        public string FirstName { get; set; }
    }
}

--------------------------------------
The web.config
--------------------------------------
XML
 <system.serviceModel>

    <behaviors>
      <serviceBehaviors>

        <behavior name="RESTServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>

      </serviceBehaviors>

      <endpointBehaviors>

        <behavior name="RESTEndPointBehavior">
          <webHttp helpEnabled="true" />
        </behavior>

      </endpointBehaviors>

    </behaviors>

    <services>
      <service name="WCFServices.Web.EmployeeService">
        <endpoint address=""
                  binding="webHttpBinding"
                  behaviorConfiguration="RESTEndPointBehavior"
                  contract="WCFServices.Web.IEmployee">
        </endpoint>
      </service>
    </services>    
    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    
  </system.serviceModel>
  
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>
Posted
Updated 28-Dec-11 17:36pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900