title: WCF RESTful JSON web service post Nested List of object
body: <p>I'm developing a WCF service that accepts parameters in JSON. I cant' figure out where I'm going wrong. Please help. </p>
  
  <p>When I test the service using fiddler, I post the following:</p>
  
  <pre><code>"locations": {
          "Departments": [{
              "Name": "Amazonas",
              "alias": "",
              "Municipalities": [{
                  "Name": "El Encanto"
              }, {
                  "Name": "La Chorrera"
              }]
  
          }]
      }
  </code></pre>
  
  <p>I get a 400 error with: "The server encountered an error processing the request. The exception message is 'OperationFormatter encountered an invalid Message body. Expected to find an attribute with name 'type' and value 'object'. Found value 'string'.'. See server logs for more details."</p>
  
  <p>The stacktrace is:</p>
  
  <pre><code>    at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
     at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
     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.ProcessMessage4(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.ProcessMessage1(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
  </code></pre>
  
  <p>Here is the contract:</p>
  
  <pre><code> [OperationContract(Name = "setFacilities")]
      [WebInvoke(
          Method = "POST",
          BodyStyle = WebMessageBodyStyle.WrappedRequest,
          ResponseFormat = WebMessageFormat.Json,
          RequestFormat = WebMessageFormat.Json,
          UriTemplate = "/setFacilities")]
      string SetFacilities(LocationData locations);
  </code></pre>
  
  <p>[UPDATE]</p>
  
  <p>Here's the LocationData class</p>
  
  <pre><code>    [Serializable]
  public class LocationData
  {
      public IList&lt;Department&gt; Departments;
  }
  
  [Serializable]
  public class Department
  {
      public string Name;
      public string Alias;
      public IList&lt;Municipality&gt; Municipalities;
  }
  
  [Serializable]
  public class Municipality
  {
      public string Name;
  }
  </code></pre>
  
  <p>What I'm I missing?</p>