自动完成扩展程序未填充
我正在尝试将 Ajax 自动完成扩展器 与 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)));
}
如前所述,我可以热服务,并且当我在 fiddler 中观看时,我会收到 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 格式返回,并且文本框会填充一个非常长的列表未定义
我错过了一些基本的东西吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题已在此处得到解决。我需要解决的问题似乎与 JSON 的包装和返回方式有关。看来 ajax 工具包自动完成扩展程序期望 JSON 内容被“.d 包装”。这是通过遵循提供的链接中的配置设置来完成的。
还应该注意的是,有一个启用 Ajax 的 WCF 项目模板添加了这些 web.config 设置...知道这可能会节省一些时间。
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.