title: How to make POST method in WCF Rest service working when data is passed in it?
body: <p>I have a wcf rest Service when i used GET method it works fine(they was passed along with the url). But i need to use post method and when there is no data to pass in post method it works fine. But when some data is added then it returns Bad Request error in IE and In mozila and chrome it just returns Error in the ajax jquery request.I have re-post this question here since i was not able to attach image..in the previous post. Please help...........</p>
  
  <p>I have post the code i used in wcf service and ajax method below.pls help.... </p>
  
  <p>Code in Ischeduler.cs</p>
  
  <pre><code>[ServiceContract]
  public interface Ischeduler
  {
  
      [OperationContract]
      [WebInvoke(Method = "POST", UriTemplate = "GetData", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
      string GetData();
  
      [OperationContract]
      [WebInvoke(Method = "POST", UriTemplate = "GetDataName", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
      string GetDataName(string Name);
  }
  </code></pre>
  
  <p>scheduler.cs</p>
  
  <pre><code>public string GetData()
      {
          string getdata = "hello";
          return string.Format("You entered" + getdata);
      }
  public string GetDataName(string Name)
      {
          return string.Format("You entered" + Name);
      }
  </code></pre>
  
  <p>Ajax request in Schedular.aspx on button click</p>
  
  <pre><code>$("#btnInvoke").click(function () {
                    $.ajax({
                        type: "POST",
                        url: "http://localhost:3125/schedulerAPI_Service/scheduler.svc/GetDataName",
                        data: '{"Name": "John"}',
                        dataType: 'json',
                        contentType: "application/json; charset=utf-8",
                        crossdomain: true,
                        success: function (data) {
                           alert(data);
                        },
                        error: function (xhr, status, error) {
                            alert("failed " + error);
                        }
                    });
  </code></pre>
  
  <p>Wcf Web Config</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
      &lt;system.web&gt;
          &lt;compilation debug="true" targetFramework="4.0"/&gt;
          &lt;pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/&gt;&lt;/system.web&gt;
      &lt;connectionStrings&gt;
          &lt;add name="InstaScribeCentralConnectionString" connectionString="Data Source=ATLT53;Initial Catalog=InstaScribeCentral;User ID=sa;Password=bmjobmjo;" providerName="System.Data.SqlClient"/&gt;
      &lt;/connectionStrings&gt;
      &lt;system.serviceModel&gt;
          &lt;behaviors&gt;
              &lt;serviceBehaviors&gt;
                  &lt;behavior name="ServiceBehavior"&gt;
                      &lt;serviceMetadata httpGetEnabled="true"/&gt;
                      &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
                  &lt;/behavior&gt;
              &lt;/serviceBehaviors&gt;
              &lt;endpointBehaviors&gt;
                  &lt;behavior name="ServiceBehavior"&gt;
                      &lt;webHttp/&gt;
                  &lt;/behavior&gt;
              &lt;/endpointBehaviors&gt;
          &lt;/behaviors&gt;
          &lt;services&gt;
              &lt;service behaviorConfiguration="ServiceBehavior" name="scheduler"&gt;
                  &lt;endpoint address="" behaviorConfiguration="ServiceBehavior" binding="webHttpBinding" contract="Ischeduler"/&gt;
              &lt;/service&gt;
          &lt;/services&gt;
          &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/NmU49.jpg" alt="enter image description here"></p>