自动填充扩展程序未填充

时间:2011-09-12 16:49:18

标签: c# .net wcf ajaxcontroltoolkit autocompleteextender

我正在尝试将Ajax Auto Complete Extender与Web项目中托管的WCF服务一起使用。已达到该服务,我已验证结果是使用fiddler返回的,但是从不填充与自动完成扩展程序关联的文本框。

服务合同如下:

[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);
}

实现只是返回一个填充的字符串列表。

aspx如下:

<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>

服务的路由在Global.asax中配置如下:

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

如前所述,我可以加热服务,当我在小提琴手中观看时,我得到JSON格式的回复。以下是Raw响应:

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"]}

可能值得注意的是,如果我从服务合同中省略了ResponseFormat,则会以XML格式返回reult,并且文本框中填充了很长的列表 undefined

我错过了一些基本的东西吗?

1 个答案:

答案 0 :(得分:2)

问题得到解决here。我需要解决的问题似乎围绕着JSON的包装和返回方式。似乎ajax工具包autocomplete extender期望JSON内容为' .d wrapped '。这是通过遵循提供的链接中的配置设置来完成的。

还应该注意,有一个支持Ajax的WCF项目模板,它添加了这些web.config设置......知道这可能会节省一些时间。