title: Serializing Array of Objects to JSON in WCF to Comply with OpenSearch
body: <p>I'm trying to write an OpenSearch Suggestion service that complies with the OpenSearch spec.</p>
  
  <p><a href="http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions" rel="nofollow noreferrer">http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions
  </a></p>
  
  <p>This spec requires the service to return a JSON array with the first element being a string and the following elements being arrays of strings.  I'm able to get it almost there by returning an array of strings (string[][]) and having WCF serialize this into JSON.  However, in order to comply with the spec, I tried to return an array of objects (object[]), with the first one being a string, and the rest being arrays of strings (string[]).</p>
  
  <p>Whenever I try to return the array of objects, it doesn't work, such as this:</p>
  
  <p>From service:</p>
  
  <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  public class SuggestionService : ISuggestionService
  {
      public object[] Search(string searchTerms)
      {
          SearchSuggestions = new object[4];
          SearchText = searchTerms;
          SearchSuggestions[0] = SearchText;
          Text = new string[10];
          Urls = new string[10];
          Descriptions = new string[10];
  
          // Removed irrelevant ADO.NET code
          while (searchResultReader.Read() &amp;&amp; index &lt; 10)
          {
  
              Text[index] = searchResultReader["Company"].ToString();
              Descriptions[index] = searchResultReader["Company"].ToString();
              Urls[index] = "http://dev.localhost/Customers/EditCustomer.aspx?id=" +
                            searchResultReader["idCustomer"];
              index++;
          }
  
          SearchSuggestions[1] = Text;
          SearchSuggestions[2] = Descriptions;
          SearchSuggestions[3] = Urls;
          return SearchSuggestions;
      }
  
      [DataMember]
      public string SearchText { get; set; }
  
      [DataMember]
      public string[] Text { get; set; }
  
      [DataMember]
      public string[] Descriptions { get; set; }
  
      [DataMember]
      public string[] Urls { get; set; }
  
      [DataMember]
      public object[] SearchSuggestions { get; set; }
  }
  </code></pre>
  
  <p>Here's the entire interface:</p>
  
  <pre><code>[ServiceContract]
  public interface ISuggestionService
  {
      [OperationContract]
      [WebGet(UriTemplate = "/Search?q={searchTerms}",
          BodyStyle = WebMessageBodyStyle.Bare,
          ResponseFormat = WebMessageFormat.Json)]
      object[] Search(string searchTerms);
  }
  </code></pre>
  
  <p>This causes the service to return "Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error."  This is the only error I've been able to get.</p>
  
  <p>Am I not able to use an array of objects to store one string and three arrays?  What else could I do in order to use WCF to return the proper JSON that complies with this spec?</p>
  
  <p>EDIT: Added lots more of the code</p>