如何使用启用了ajax的wcf服务使用自动完成扩展器 [英] how to use autocomplete extender using ajax enabled wcf service

查看:78
本文介绍了如何使用启用了ajax的wcf服务使用自动完成扩展器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的前端代码

This is my front end code

<body>
    <form id="form1" runat="server">
 <ajaxToolkit:ToolkitScriptManager runat="server" ID="ScriptManager1"   EnablePageMethods = "true"></ajaxToolkit:ToolkitScriptManager>

   <div>
   <asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />
<ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server"

  EnableCaching="true"

  BehaviorID="AutoCompleteEx"

  MinimumPrefixLength="1"

  TargetControlID="myTextBox"

  ServicePath="~/vijay.svc"

  ServiceMethod="getautocomplete"

  FirstRowSelected = "false"

  CompletionInterval="100"

  CompletionSetCount="20"

  CompletionListCssClass="autocomplete_completionListElement"

  CompletionListItemCssClass="autocomplete_listItem"

  CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"

  DelimiterCharacters=";, :"

Enabled="true"

  ShowOnlyCurrentWordInCompletionListItem="true">


 </ajaxToolkit:AutoCompleteExtender>
 <asp:ImageButton ID="ImageButton1" runat="server" Height="23px"

                ImageUrl="images/search_btn.gif"

                Width="29px" onclick="ImageButton1_Click" />


    </div>
    </form>
</body>




这是我在WCF服务中的代码




This is my code in WCF service

[OperationContract]
    public List<string> getautocomplete(string prefix,int count)
    {
        List<string> str = new List<string>();
        DBDataContext db = new DBDataContext();
        var v = from i in db.fg0uv000s
                where System.Data.Linq.SqlClient.SqlMethods.Like(i.UnivID, prefix+"%")
                select new
                {
                    i
                    .UnivID
                };
        foreach (var i in v)
        {
            string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(i.UnivID,i.UnivID);
            str.Add(item);

        }
        return str;

    }



空值从前端传递到启用了Ajax的Wcf服务.类似的代码对于正常的Wcf服务正常工作.

谁能帮助我找出为什么将null值传递给wcf服务.


谢谢
Sirisha



Null value is being passed to my Ajax enabled Wcf service from front end. Similar code is working fine for Normal Wcf service.

Can anyone help me to find out why null value is being passed to wcf service.


Thank you
Sirisha

推荐答案

尝试向ScriptManager注册服务:

Try registering the service with ScriptManager:

<asp:ScriptManager ID="ScriptManager1" runat="server"  EnablePageMethods = "true">
            <Services>
                <asp:ServiceReference Path="~/vijay.svc" />
            </Services>
</asp:ScriptManager>



同时检查您的服务等级,它应该具有
[System.Web.Script.Services.ScriptService]
已应用属性(当VS创建新服务时,默认情况下,它在注释下).

您可能还需要将[System.Web.Script.Services.ScriptMethod]属性应用于getautocomplete方法.



Also check your service class, it should have
[System.Web.Script.Services.ScriptService]
attribute applied (when VS creates new service it''s under comments by default).

You might also need to apply [System.Web.Script.Services.ScriptMethod] attribute to getautocomplete method.


您好...请观看本文. -us/library/bb628607.aspx> http://msdn.microsoft.com/en-us/library/bb628607.aspx [
hi... watch this Article.. http://msdn.microsoft.com/en-us/library/bb628607.aspx[^]


感谢您的回复
但它不起作用.............................
thanks for your rply
but its not working....................


这篇关于如何使用启用了ajax的wcf服务使用自动完成扩展器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆