title: Using WCF services as Restful Architecture
body: <p>I am trying to convert my wcf services to a restful architecture. I started by converting a service called ConnectToApplication which checks user permission for authentification purposes in order to support POST requests. While trying Ajax to query the service using the following javascript code:</p>
  
  <pre><code>   var formData={"userName":"admin", "password":"act;2016@","ApplicationName":"actior"}
  
  
          $.ajax({
              url : "http://localhost:10220/AdministrationService/ConnectToApplication",
              type: "POST",
              data: formData,
  
  
  
              success: function (data) { 
              alert('success');
              },
                error: function(XMLHttpRequest, textStatus, errorThrown) { 
                             alert("Status: " + textStatus); alert("Error: " + errorThrown); 
                 } 
  
          });
  </code></pre>
  
  <p>I got an HTTP 400(Bad request) with the following error:</p>
  
  <blockquote>
    <p>The server encountered an error processing the request. The exception
    message is 'The incoming message has an unexpected message format
    'Raw'. The expected message formats for the operation are 'Xml';
    'Json'. This can be because a WebContentTypeMapper has not been
    configured on the binding. See the documentation of
    WebContentTypeMapper for more details.'. See server logs for more
    details. The exception stack trace is:</p>
    
    <p>at
    System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message
    message, Object[] parameters) at
    System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message
    message, Object[] parameters) at
    System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message
    message, Object[] parameters) at
    System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp;
    rpc) at
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;
    rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean
    isOperationContextSet)</p>
  </blockquote>
  
  <p>Here is my metadata for endpoint configuration:</p>
  
  <pre><code>  [OperationContract]
           [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "ConnectToApplication/")]
  
          UserPermessionDTO ConnectToApplication(string userName, string password, string ApplicationName); 
  </code></pre>
  
  <p>Here is my WCF configuration:</p>
  
  <pre><code>    &lt;services&gt;
        &lt;service name="ActiorServeurConsoleApp.AdministrationService" behaviorConfiguration="serviceBehavior"&gt;
              &lt;endpoint address="" binding="webHttpBinding" contract="ActiorServeurConsoleApp.IAdministrationService"
                        behaviorConfiguration="web"&gt;
                &lt;identity&gt;
                  &lt;dns value="localhost" /&gt;
                &lt;/identity&gt;
              &lt;/endpoint&gt;
  
              &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
              &lt;host&gt;
                &lt;baseAddresses&gt;
                  &lt;add baseAddress="http://localhost:10220/AdministrationService/" /&gt;
                &lt;/baseAddresses&gt;
              &lt;/host&gt;
            &lt;/service&gt;
      &lt;services&gt;
  
  
      &lt;serviceBehaviors&gt;
        &lt;behavior name="serviceBehavior"&gt;
                &lt;serviceMetadata httpGetEnabled="false"/&gt;
                &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
              &lt;/behavior&gt;
       &lt;/serviceBehaviors&gt;
  
    &lt;behavior name="serviceBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="false"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
  </code></pre>