I'm trying to write an OpenSearch Suggestion service that complies with the OpenSearch spec.
http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions
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[]).
Whenever I try to return the array of objects, it doesn't work, such as this:
From service:
[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() && index < 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; }
}
Here's the entire interface:
[ServiceContract]
public interface ISuggestionService
{
[OperationContract]
[WebGet(UriTemplate = "/Search?q={searchTerms}",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json)]
object[] Search(string searchTerms);
}
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.
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?
EDIT: Added lots more of the code