2011-09-12 71 views
2

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

服务合同如下:

[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格式的回复。以下是原始响应:

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,该reult以XML格式返回和文本框中,填入一个很长的名单undefined

我是否缺少一些基本的东西?

回答

2

问题已解决here。我需要解决的问题似乎围绕着JSON被包装和返回的方式。看来ajax工具包自动完成扩展程序期望JSON内容为'.d包装'。这是通过遵循提供的链接中的配置设置完成的。

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