title: Remove internal "__type" tags in ASP.NET Restful WCF
body: <p>I'm developing a RESTful WCF, and am currently having trouble getting nice, clean JSON-serialized return values.</p>
  
  <p><a href="https://stackoverflow.com/questions/7590088/make-asp-net-wcf-convert-dictionary-to-json-omitting-key-value-tags">A little while back, I got rid of "Key" and "Value" tags</a> around each of my keys and values (caused by serializing a <code>Dictionary&lt;string, object&gt;</code> object) by using a wrapper.</p>
  
  <p>But when I did that, "__type" tags started showing up.  I managed to get rid of the "d" tag, along with the first "__type" tag by replacing WebScriptServiceHostFactory with WebServiceHostFactory in the ServiceHost tag of my svc file.</p>
  
  <p>So my result looks like this:</p>
  
  <pre><code>{"Status":"Success","Data":{"__type":"SerializableDictionaryOfstringanyType:#MyNamespace.MyFolder","Key1":"Value1","Key2":"Value2","Key3":"Value3"}}
  </code></pre>
  
  <p>But I want it to look like this:</p>
  
  <pre><code>{"Status":"Success","Data":{"Key1":"Value1","Key2":"Value2","Key3":"Value3"}}
  </code></pre>
  
  <p>My test webservice code looks like this:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
  public SerializableDictionary&lt;string, object&gt; Test1(String Token, String Id)
  {
      DataTable testTable = new DataTable();
      testTable.Columns.Add("Key1", typeof(System.String));
      testTable.Columns.Add("Key2", typeof(System.String));
      testTable.Columns.Add("Key3", typeof(System.String));
  
      DataRow testRow = testTable.NewRow();
      testRow["Key1"] = "Value1";
      testRow["Key2"] = "Value2";
      testRow["Key3"] = "Value3";
  
      testTable.Rows.Add(testRow);
  
      return SuccessfulResult(testTable);
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> And the SuccessfulResult function looks like this (sorry for forgetting it):</p>
  
  <pre><code>private SerializableDictionary&lt;string, object&gt; SuccessfulResult(DataTable dt = null)
  {
      SerializableDictionary&lt;string, object&gt; result = new SerializableDictionary&lt;string, object&gt;();
      result.Add("Status", "Success");
  
      if (dt == null || dt.Rows.Count != 1)
          return result;
  
      SerializableDictionary&lt;string, object&gt; dct = new SerializableDictionary&lt;string, object&gt;();
      foreach (DataColumn currCol in dt.Rows[0].Table.Columns)
          dct.Add(currCol.ColumnName, dt.Rows[0][currCol.ColumnName].ToString());
  
      result.Add("Data", dct);
  
      return result;
  }
  </code></pre>
  
  <p>If anybody has any ideas on how I might get rid of that last little "__type" tag, I would love to hear them!  Thanks very much, and let me know if there's anything else I can post that might be helpful.</p>