Asp.net Ajax AutoCompleteXtender不调用wcf服务

Asp.net Ajax AutoCompleteXtender不调用wcf服务,asp.net,ajax,wcf,Asp.net,Ajax,Wcf,我在asp.NET4.0(vs2010)中工作。我正在尝试实现AutoCompleteXtender ajax控件。起初我尝试使用page方法,但由于usercontrol中有extender,因此无法使用此方法。我花了几天时间进行研究,确定需要使用支持Ajax的WCF服务。所以我做了这个。我脱离了我的应用程序,创建了一个测试应用程序,它模仿了我正在尝试做的事情,并且工作正常。我把控件放在页面上,指向服务,瞧,它触发了事件,效果很好。因此,我将带有必要更改的代码移植到我的主应用程序,但它不起作用

我在asp.NET4.0(vs2010)中工作。我正在尝试实现AutoCompleteXtender ajax控件。起初我尝试使用page方法,但由于usercontrol中有extender,因此无法使用此方法。我花了几天时间进行研究,确定需要使用支持Ajax的WCF服务。所以我做了这个。我脱离了我的应用程序,创建了一个测试应用程序,它模仿了我正在尝试做的事情,并且工作正常。我把控件放在页面上,指向服务,瞧,它触发了事件,效果很好。因此,我将带有必要更改的代码移植到我的主应用程序,但它不起作用。我所说的“不起作用”是指它不会在服务中触发事件。我怀疑问题在于ServicePath,但我尝试了许多不同的途径,但似乎没有任何效果。 以下是来自控件的代码:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
    <div style="float: left">
        <asp:Label runat="server">Site Id:</asp:Label><br />
        <asp:TextBox ID="txtSiteId" runat="server" AutoPostBack="True"     OnTextChanged="TextChangedEvent"></asp:TextBox>
    </div>
    <div style="float: left; width: 200px; padding-left: 20px; margin-right: 5px">
        <asp:Label runat="server">Entered Site Id's:</asp:Label><br />
        <asp:Repeater ID="rptSiteIds" runat="server" OnItemCommand="rptSiteIds_ItemCommand">
            <ItemTemplate>
                <asp:LinkButton id="lnkRemove" Width="50" runat="server" Text="remove" CommandName="remove"></asp:LinkButton>
                <asp:Label ID="lblItem" runat="server" Text='<%# Eval("Item") %>'></asp:Label>
            </ItemTemplate>
            <SeparatorTemplate>
                <br>
            </SeparatorTemplate>
        </asp:Repeater>
    </div>

    <Controls:ConfirmationModal runat="server" ID="MaxSiteIdConfirmation" ModalType="Alert" OnOkClicked="ConfirmationOk_Clicked"
        Title="Site Id Validation" Message="Too many site id's"
        Width="300" />

    <ajaxToolkit:AutoCompleteExtender
        runat="server"
        ID="AutoCompleteExtender"
        TargetControlID="txtSiteId" 
        CompletionSetCount="10"
        UseContextKey="True"
        ServicePath="~\DataServices\WebDataServices.svc"
        ServiceMethod="GetCompletionList" />


</ContentTemplate>
}


任何帮助都将不胜感激。

您需要做几件事:

您的服务方法需要使用以下属性进行修饰:

[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
更新OperationContract属性,使其如下所示:

[OperationContract WebInvoke(Method="POST", ResponseFormat = WebMessageFormat.Json)]
在方法中的
return autoCompleteWordList
语句之前添加以下代码段

    if (WebOperationContext.Current != null)
        WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
另外,请确保可以从web浏览器正确执行web服务调用,并且所有元数据信息都正确显示。您是否已将任何端点信息添加到web.config文件中

如果行得通,请告诉我

    if (WebOperationContext.Current != null)
        WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";