我正在尝试将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,结果将以 XML 格式返回,并且文本框会填充一个很长的未定义列表
我错过了一些基本的东西吗?