title: How to allow the Post method in the http request?
body: <p>I am trying to create a RESTFul service with the standard HTTP verbs (GET, POST, PUT, DELETE). I use classic WCF service with RESTful annotation. My issue is that I get a "method not allowed" when requesting my service with POST.</p>
  
  <p>Note: I am using IIS 8.5 asp.net </p>
  
  <p>Here is my code:</p>
  
  <p><strong>Web.config:</strong></p>
  
  <pre><code> &lt;customHeaders&gt;
        &lt;add name="Access-Control-Allow-Origin" value="http://localhost" /&gt;
        &lt;add name="Access-Control-Allow-Headers" value="Content-Type, Accept, X-Requested-With" /&gt;
        &lt;add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE"/&gt;
        &lt;add name ="cache-control" value ="private, max-age=0, no-cache"/&gt;
      &lt;/customHeaders&gt; 
  </code></pre>
  
  <p><strong>UserService.svc:</strong></p>
  
  <pre><code>using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Runtime.Remoting.Messaging;
          using System.Runtime.Serialization;
          using System.ServiceModel;
          using System.ServiceModel.Web;
          using System.Text;
  
          namespace MyApp.WS
          {
          [ServiceContract]
  public interface UserService
  {
      //POST operation
      [OperationContract]
          [WebInvoke(Method = "POST",
                     ResponseFormat = WebMessageFormat.Json,
                     RequestFormat = WebMessageFormat.Json,
                     BodyStyle = WebMessageBodyStyle.Bare,
                     UriTemplate = "/Users")]
      UserDTO CreateUser(UserDTO createUser);
  
      //Get Operation
      [OperationContract]
          [WebGet(UriTemplate = "/Users", ResponseFormat = WebMessageFormat.Json)]
      List&lt;UserDTO&gt; GetAllUsers();
  
      [OperationContract]
          [WebGet(UriTemplate = "/Users/{id}", ResponseFormat = WebMessageFormat.Json)]
      UserDTO GetAUser(string id);
  
      //PUT Operation
      [OperationContract]
          [WebInvoke(UriTemplate = "/Users/{id}", Method = "PUT", ResponseFormat = WebMessageFormat.Json)]
      UserDTO UpdateUser(string id, UserDTO updateUser);
  
      //DELETE Operation
      [OperationContract]
          [WebInvoke(UriTemplate = "/Users/{id}", Method = "DELETE", ResponseFormat = WebMessageFormat.Json)]
      void DeleteUser(string id);
  
  
  }
  
  }
  </code></pre>
  
  <p><strong>And UserServiceImpl.svc:</strong></p>
  
  <pre><code>using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Runtime.Serialization;
          using System.ServiceModel;
          using System.ServiceModel.Activation;
          using System.ServiceModel.Web;
          using System.Text;
          using AutoMapper;
          using MyApp.Model;
  
  
          namespace MyApp.WS
          {
          // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
          // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
          [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
          [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
  public class UserServiceImpl : UserService
          {
  
  public MyApp.Controller.UserController UserControllerImpl{get;set;}
  
  
  public UserDTO CreateUser(UserDTO createUser)
  
          {
  
          User user = Mapper.Map&lt;User&gt;(createUser);
          user = UserControllerImpl.Save(user);
  
  
          return Mapper.Map&lt;UserDTO&gt;(user);
          }
  
  public List&lt;UserDTO&gt; GetAllUsers()
          {
  
          // var u = new UserDTO();
          //// u.ID = 3;
          // u.Name = "coucou";
          // u.DateCreate = DateTime.Now;
  
          // CreateUser(u);
  
  
  
          var result = UserControllerImpl.GetAll();
          return Mapper.Map &lt;List&lt;User&gt;,List&lt;UserDTO&gt;&gt;(result);
  
  
  
          }
  
  public UserDTO GetAUser(string id)
          {
          var result = UserControllerImpl.Get(int.Parse(id));
  
          return Mapper.Map&lt;UserDTO&gt;(result);
          }
  
  public UserDTO UpdateUser(string id, UserDTO updateUser)
          {
          updateUser.id = int.Parse(id);
          var user = Mapper.Map&lt;User&gt;(updateUser);
          UserControllerImpl.Update(user);
  
          return Mapper.Map&lt;UserDTO&gt;(user);
  
          }
  
  public void DeleteUser(string id)
          {
          UserControllerImpl.Delete(int.Parse(id));
          }
  
  
          }
          }
  </code></pre>
  
  <p>normally, in my web.config with this customheader I would like have the permission to send a post ajax $</p>
  
  <p>Actually I have request GET it's good but not good for the request POST </p>
  
  <p>I don't understand good when the server send this error message 
  it's possible to help me ? thanks </p>