title: WCF POST method get error 400 Bad Request
body: <p>I am using WCF POST method, once i added parameter POST to the service its return error 400 Bad Request, if i left the parameter empty it can access to my service.</p>
  
  <p>This is my Interface:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  using System.ServiceModel.Web;
  using System.IO;
  namespace SampleArticle
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IRestService" in both code and config file together.
      [ServiceContract(Namespace="IRestService/JSONData")]
      public interface IRestService
      {
  
          [OperationContract]
          [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate = "authorize")]
          Stream authorize(Stream streamdata);
  
      }
  }
  </code></pre>
  
  <p>This is my Web.config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  
    &lt;appSettings&gt;
  
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
  
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
  
    &lt;/system.web&gt;
  
    &lt;system.serviceModel&gt;
  
  
      &lt;services&gt;
        &lt;service name="SampleArticle.RestService" behaviorConfiguration="serviceBehavior"&gt;
          &lt;endpoint address="" binding="webHttpBinding" contract="SampleArticle.IRestService" behaviorConfiguration="web"&gt;&lt;/endpoint&gt;        
        &lt;/service&gt;
      &lt;/services&gt;
  
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
  
          &lt;behavior name="serviceBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
          &lt;/behavior&gt;
  
        &lt;/serviceBehaviors&gt;
  
        &lt;endpointBehaviors&gt;
          &lt;behavior name="web"&gt;
            &lt;webHttp /&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
  
      &lt;/behaviors&gt;
  
      &lt;protocolMapping&gt;
        &lt;add binding="basicHttpsBinding" scheme="https" /&gt;
      &lt;/protocolMapping&gt;
  
  
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
  
  
   &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
     &lt;directoryBrowse enabled="true" /&gt;
  
    &lt;/system.webServer&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Im using Msxml2.ServerXMLHTTP to POST</p>
  
  <pre><code>Dim objXmlHttpMain , URL
  
  URL="http://localhost/SampleArticle/RestService.svc/authorize" 
  
  strJSONToSend = "{""acctId"": ""Test10001"","
  strJSONToSend = strJSONToSend &amp; """language"": 200,"
  strJSONToSend = strJSONToSend &amp; """Code"": ""Test"","
  strJSONToSend = strJSONToSend &amp; """token"": ""abcd123412341234"","
  strJSONToSend = strJSONToSend &amp; """serialNo"": ""20161020160455982841""}"
  
  // if i set the parameter to empty i can access to the service
  'strJSONToSend  = ""
  Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP") 
  'on error resume next 
  objXmlHttpMain.open "POST",URL, False 
  
  // if i change the  "application/json" to "application/x-www-form-urlencoded" it works 
  'objXmlHttpMain.setRequestHeader "Content-Type", "application/json"
  objXmlHttpMain.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  
  objXmlHttpMain.send strJSONToSend 
  
  
  //check for output
  S = objXmlHttpMain.responseText
  response.write S
  
  set objJSONDoc = nothing 
  set objResult = nothing
  </code></pre>
  
  <p>Server log msg</p>
  
  <blockquote>
    <p>Incoming message for operation 'authorize' (contract 'IRestService' with namespace 'IRestService/JSONData') contains an unrecognized http body format value 'Json'. The expected body format value is 'Raw'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.</p>
  </blockquote>
  
  <p>if i change the Content-Type "application/json" to "application/x-www-form-urlencoded" 
  it works , but i need the data in JSON format.
  Is there any setting i am missing with ? Please advice.</p>