title: Serializing a class to JSON generated by xsd.exe using WCF
body: <p>I want to write a RESTful Webservice with WCF which is able to reply in JSON and XML. I have a XML schema from which I generated my classes by using <code>xsd.exe</code>. Everthing works fine as long as I request XML, but it fails if I want JSON as response. </p>
  
  <p>The <code>System.ServiceModel.Dispatcher.MultiplexingDispatchMessageFormatter</code> throws a <code>System.Collections.Generic.KeyNotFoundException</code>. The problem is, what I found out so far, that <code>xsd.exe</code> does not generate <code>DataContract</code> and <code>DataMember</code> Attributes. Is there any solution to this where I do not need to use the <code>SvcUtil.exe</code>, because therefore I would need to change my schema..</p>
  
  <p>That is the code where it fails, <code>JsonDispatchMessageFormatter</code> is of the type <code>MultiplexingDispatchMessageFormatter</code>. (Which is the default type anyway)</p>
  
  <pre><code>var headers = requestProperty.Headers[HttpRequestHeader.Accept] ?? requestProperty.Headers[HttpRequestHeader.ContentType];
  if (headers != null &amp;&amp; headers.Contains("application/json"))
  {
      return this.JsonDispatchMessageFormatter.SerializeReply(messageVersion, parameters, result);
  }
  </code></pre>
  
  <p>Generated code:</p>
  
  <pre><code>[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(Namespace="...")]
  [System.Xml.Serialization.XmlRootAttribute(Namespace="...", IsNullable=false)]
  public partial class Incident {        
      private long incidentIdField;
  
      /// &lt;remarks/&gt;
      public long IncidentId {
          get {
              return this.incidentIdField;
          }
          set {
              this.incidentIdField = value;
          }
      }
  }
  </code></pre>