title: Post JSON Array to WCF Rest Service Results in Empty Parameters. DataContract?
body: <p>I am attempting to create a restful web service in dotnet (VS 2012) that accepts a JSON list. There is this very helpful post. </p>
  
  <p><a href="https://stackoverflow.com/questions/6323338/jquery-ajax-posting-json-to-webservice">Jquery Ajax Posting json to webservice</a></p>
  
  <p>The example is spot on, but I need the DataContract sorted. Here is my problem:</p>
  
  <p>Fiddler posts:</p>
  
  <pre><code> { "Markers": [
   { "position": "128.3657142857143", "markerPosition": "7" },
   { "position": "235.1944023323615", "markerPosition": "19" },
   { "position": "42.5978231292517", "markerPosition": "-3" }
   ]};
  </code></pre>
  
  <p>In the VS2012 Debugger I see the equivalent:</p>
  
  <pre><code> { "Markers": [
   { "position": "0", "markerPosition": "0" },
   { "position": "0", "markerPosition": "0" },
   { "position": "0", "markerPosition": "0" }
   ]};
  </code></pre>
  
  <p>Here is the code (straight from the linked example):</p>
  
  <pre><code>public class Marker
  {
     decimal position { get; set; }
     int markerPosition { get; set; }
  }
  
  public string CreateMarkers(List&lt;Marker&gt; Markers)
  {
     return "Received " + Markers.Count + " markers.";
  }
  </code></pre>
  
  <p>Here is the contract:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(UriTemplate = "Markers", Method = "POST", ResponseFormat =    WebMessageFormat.Json,
  RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
  string CreateMarkers(List&lt;Marker&gt; Markers);
  </code></pre>
  
  <p>This other, equally wonderful, post explains that the datacontract needs to be set to see the parameter values:</p>
  
  <p><a href="https://stackoverflow.com/questions/6835872/wcf-rest-post-of-json-parameter-is-empty">WCF REST POST of JSON: Parameter is empty</a></p>
  
  <p>My original question was what should the data contract be. I started with:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(UriTemplate = "Markers", Method = "POST", ResponseFormat =           WebMessageFormat.Json,
  RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
  string CreateMarkers(List&lt;Marker&gt; Markers);
  </code></pre>
  
  <p>After which the message structure comes through, but null content. Then, upon suggestion, I've tried:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(UriTemplate = "Markers", Method = "POST", ResponseFormat =           WebMessageFormat.Json,
  RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
  string CreateMarkers(List&lt;Marker&gt; Markers);
  </code></pre>
  
  <p>After which the message structure and the content were null.</p>
  
  <pre><code> [OperationContract]
      [WebInvoke(UriTemplate = "WrappedMarkers", Method = "POST", ResponseFormat = WebMessageFormat.Json,
          RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
      string WrappedMarkers(MarkerRequest wrappedmarkers);
  
   [DataContract]
    public class MarkerRequest
    {
      [DataMember]
      public List&lt;Marker&gt; Markers 
      { 
          get { return _markers; }
          set { _markers = value; } 
      }
  
     private List&lt;Marker&gt; _markers = new List&lt;Marker&gt;(); 
  }
  
  
   public string WrappedMarkers(MarkerRequest wrappedmarkers)
      {
          return wrappedmarkers.Markers.ToString();
      }
  </code></pre>
  
  <p>Here is the operations contracted, changed to WrappedRequest</p>
  
  <p>The structure was correct, but the content was again null.</p>
  
  <p>Back to square one. I seem to be able to see the structure of the message. How do I get the content mapped to the structure?</p>