自动完成扩展程序未填充

发布于 2024-12-04 05:14:35 字数 2396 浏览 2 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫轩蝶泪 2024-12-11 05:14:35

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文