Question

I am trying to utilize the Ajax Auto Complete Extender with a WCF service that is hosted in the web project. The service is reached and I have verified that results are returned with fiddler, however the text box associated with the auto complete extender is never populated.

The service contract is as follows:

[ScriptService]
[ServiceContract(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public interface ICertificateService
{
    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.Wrapped,
        ResponseFormat = WebMessageFormat.Json)]
    List<string> GetCompletionList(string prefixText, int count);
}

The implementation is just returning a populated list of string.

The aspx is as follows:

<asp:TextBox runat="server" ID="aceInstructors"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender runat="server" 
                                  ID="autoCompleteInstructor"
                                  TargetControlID="aceInstructors"
                                  ServiceMethod="GetCompletionList" 
                                  ServicePath="../../CertificateService" 
                                  MinimumPrefixLength="1"
                                  CompletionInterval="1000" 
                                  EnableCaching="true" CompletionSetCount="5">
                        <Animations>
                            <OnShow>  <HideAction Visible="true" /> </OnShow>
                            <OnHide> <HideAction Visible="false" /> </OnHide>       
                        </Animations>

The route for the service is configured in Global.asax as follows:

private void RegisterRoutes()
    {
        RouteTable.Routes.Add(new ServiceRoute("CertificateService", new WebServiceHostFactory(), typeof(CertificateService)));
    }

As stated before I can hot the service and I get a response in JSON format when I watch in fiddler. The following is the Raw response:

HTTP/1.1 200 OK
Server: Cassini/4.0.1.7
Date: Mon, 12 Sep 2011 16:44:16 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 68
Cache-Control: private
Content-Type: application/json; charset=utf-8
Connection: Close

{"GetCompletionListResult":["Alpha","Beta","Gamma","Delta","Omega"]}

Something possibly worth noting is that if I omit the ResponseFormat from the Service contract, the reult is returned in XML Format and the text box is populated with a very long list undefined

Am I missing something basic?

Was it helpful?

Solution

The problem was addressed here. The issue that I needed to resolve seemed to revolve around the way JSON is wrapped and returned. It appears that the ajax tool kit autocomplete extender is expecting the JSON content to be '.d wrapped'. This was accomplished by following the configuration settings in the provided link.

It should also be noted that there is an Ajax-Enabled WCF project template that adds these web.config settings...knowing that probably would have saved some time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top