Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You posted a bunch of [DataMember]'s. Please post the entire [DataContract]. Also show us the JSON returned when you return that DataContract.</p> <hr> <p>A Data Contract should never include behavior. Try the following (I haven't had a chance to test it, and will need to fake up the data to do so):</p> <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class SuggestionService : ISuggestionService { public SearchResults Search(string searchTerms) { var results = new SearchResults { SearchText = searchTerms, Text = new string[10], Urls = new string[10], Descriptions = new string[10] }; // Removed irrelevant ADO.NET code int index = 0; while (searchResultReader.Read() &amp;&amp; index &lt; 10) { results.Text[index] = searchResultReader["Company"].ToString(); results.Descriptions[index] = searchResultReader["Company"].ToString(); results.Urls[index] = "http://dev.localhost/Customers/EditCustomer.aspx?id=" + searchResultReader["idCustomer"]; index++; } return results; } } [DataContract] public class SearchResults { [DataMember] public string SearchText { get; set; } [DataMember] public string[] Text { get; set; } [DataMember] public string[] Descriptions { get; set; } [DataMember] public string[] Urls { get; set; } } </code></pre> <hr> <p>Ok, I read enough of that spec and of the JSON spec, to convince myself you really do need to return an array of objects, and not an instance of a class that contains an array of objects. Of course, that didn't quite work. Here's what you needed:</p> <pre><code>[ServiceContract] [ServiceKnownType(typeof(string))] [ServiceKnownType(typeof(string[]))] public interface ISuggestionService { [OperationContract] [WebGet(UriTemplate = "/Search?q={searchTerms}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] object[] Search(string searchTerms); } </code></pre> <p>I just tried it, and it worked. Here's the JSON (indentation added):</p> <pre><code>[ "abc", ["Company1","Company2","Company3",...], ["Company1 Description","Company2 Description","Company3 Description",...], ["http:\/\/dev.localhost\/Customers\/EditCustomer.aspx?id=1", "http:\/\/dev.localhost\/Customers\/EditCustomer.aspx?id=2", "http:\/\/dev.localhost\/Customers\/EditCustomer.aspx?id=3",...] ] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload