title: WCF not deserializing JSON input
body: <p>I have a WCF service defined as follows:</p>
  
  <pre><code>Imports System.ServiceModel
  Imports System.ServiceModel.Web
  
  &lt;ServiceContract()&gt;
  Public Interface ILayoutService
  
    &lt;OperationContract()&gt;
    &lt;WebInvoke(Method:="POST",
               BodyStyle:=WebMessageBodyStyle.WrappedRequest,
               RequestFormat:=WebMessageFormat.Json,
               ResponseFormat:=WebMessageFormat.Json)&gt;
    Sub SaveLayout(ByVal layout As Layout)
  
    &lt;OperationContract()&gt;
    Function GetLayout() As Layout
  
  End Interface
  </code></pre>
  
  <p>The <code>Layout</code> class is defined as:</p>
  
  <pre><code>Imports System.Runtime.Serialization
  
  &lt;DataContract()&gt;
  Public Class Layout
  
    &lt;DataMember()&gt;
    Public Property Columns As New List(Of ContentColumn)
  
  End Class
  
  &lt;DataContract()&gt;
  Public Class ContentColumn
    &lt;DataMember()&gt;
    Public Property Name As String = "Column Name"
  
    &lt;DataMember()&gt;
    Public Property Position As Integer
  
    &lt;DataMember()&gt;
    Public Property Modules As New List(Of ContentModule)
  
  End Class
  
  &lt;DataContract()&gt;
  Public Class ContentModule
  
    &lt;DataMember()&gt;
    Public Property Name As String = "Module Name"
  
    &lt;DataMember()&gt;
    Public Property Position As Integer
  
  End Class
  </code></pre>
  
  <p>The implementation of ILayoutService is as follows:</p>
  
  <pre><code>Imports System.ServiceModel.Activation
  Imports System.Web.Script.Serialization
  
  &lt;AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Required)&gt;
  Public Class LayoutService
    Implements ILayoutService
  
    Public Sub SaveLayout(ByVal layout As Layout) Implements ILayoutService.SaveLayout
      Dim l As New Layout
      Dim left, center, right As New ContentColumn
  
      left.Name = "Left Column"
      left.Position = 0
      center.Name = "Center Column"
      center.Position = 1
      right.Name = "Right Column"
      right.Position = 2
  
      Dim topLeft, centerLeft, bottomLeft, topCenter, centerCenter, bottomCenter, topRight, centerRight, bottomRight As New ContentModule
  
      topLeft.Name = "Top Left"
      topLeft.Position = 0
      centerLeft.Name = "Center Left"
      centerLeft.Position = 1
      bottomLeft.Name = "Bottom Left"
      bottomLeft.Position = 2
  
      topCenter.Name = "Top Center"
      topLeft.Position = 0
      centerCenter.Name = "Center Center"
      centerCenter.Position = 1
      bottomCenter.Name = "Bottom Center"
      bottomCenter.Position = 2
  
      topRight.Name = "Top Right"
      topRight.Position = 0
      centerRight.Name = "Center Right"
      centerRight.Position = 1
      bottomRight.Name = "Bottom Right"
      bottomRight.Position = 2
  
      left.Modules.Add(topLeft)
      left.Modules.Add(centerLeft)
      left.Modules.Add(bottomLeft)
  
      center.Modules.Add(topCenter)
      center.Modules.Add(centerCenter)
      center.Modules.Add(bottomCenter)
  
      right.Modules.Add(topRight)
      right.Modules.Add(centerRight)
      right.Modules.Add(bottomRight)
  
      l.Columns.Add(left)
      l.Columns.Add(center)
      l.Columns.Add(right)
  
      Dim json As New JsonResult
      json.Data = l
      Dim serializer As New JavaScriptSerializer
      Dim output = serializer.Serialize(json.Data)
    End Sub
  
    Public Function GetLayout() As Layout Implements ILayoutService.GetLayout
      Dim l As New Layout
      Dim c As New ContentColumn
      Dim m As New ContentModule
      c.Modules.Add(m)
      l.Columns.Add(c)
      Return l
    End Function
  End Class
  </code></pre>
  
  <p>I implemented <code>SaveLayout()</code> so I can get the literal JSON that would be (de)serialized. I'm using that to test invoking this service via jQuery:</p>
  
  <pre><code>$(document).ready(function () {
  
    $("#saveLayout").click(function () {
  
      var layout = buildLayout();
      var jsonLayout = $.toJSON(layout);
  
      $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        url: "/Services/LayoutService.svc/SaveLayout",
        data: jsonLayout,
        dataType: "json",
        success: function (result) {
          alert(result.d.Columns[0].Name);
        },
        error: function (xhr, ajaxOptions, thrownError) {
          var jsonFault = JSON.parse(xhr.responseText);
          alert(jsonFault.Message);
        }
      });
      return false;
    });
  
  });
  
  function buildLayout() {
    var layout = { "Columns": [
      { "Name": "Left Column", "Position": 0, "Modules": [
        { "Name": "Top Left", "Position": 0 },
        { "Name": "Center Left", "Position": 1 },
        { "Name": "Bottom Left", "Position": 2}]
      },
      { "Name": "Center Column", "Position": 1, "Modules": [
        { "Name": "Top Center", "Position": 0 },
        { "Name": "Center Center", "Position": 1 },
        { "Name": "Bottom Center", "Position": 2}]
      },
      { "Name": "Right Column", "Position": 2, "Modules": [
        { "Name": "Top Right", "Position": 0 },
        { "Name": "Center Right", "Position": 1 },
        { "Name": "Bottom Right", "Position": 2}]
      }]
    };
  
    return layout;
  }
  </code></pre>
  
  <p>The layout returned by <code>buildLayout()</code> is the exact JSON returned by the <code>serialize()</code> call in the VB code. For some reason, when I invoke the web service, the input parameter <code>layout</code> in <code>SaveLayout()</code> is Nothing. Something must be failing on deserialization. Any idea why?</p>