Autocomplete using webservice

Last post 11-19-2009 3:27 PM by MrDean. 2 replies.

Sort Posts:

  • Autocomplete using webservice

    11-18-2009, 7:52 AM
    • Member
      point Member
    • MrDean
    • Member since 11-16-2009, 8:59 AM
    • Posts 30

    Hello all - as per my other posts, excuse my ignorance, I am new to this and finding myself quite out of my depth at the moment!

    Ok, I have set up a text box with an auto complete extender attached that is populated using a web service, et voila:

    <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
            <asp:ServiceReference InlineScript="false" Path="~/GetProd.asmx" />
            </Services>
            </asp:ScriptManager>
            
            
            <asp:TextBox ID="txtProDesSearch" AutoComplete="off" Autocompletetype="Search" runat="server"></asp:TextBox>
             
             
            <cc1:AutoCompleteExtender ID="txtProDesSearch_AutoCompleteExtender" 
                runat="server" 
                DelimiterCharacters="" 
                TargetControlID="txtProDesSearch"
                Enabled="True" 
                ServiceMethod="GetProdDesSearch" 
                ServicePath="~/GetProd.asmx"
                CompletionSetCount="10" EnableCaching="true" MinimumPrefixLength="3" 
                CompletionInterval="10">
            </cc1:AutoCompleteExtender>
    
    ---------
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    
    /// <summary>
    /// Summary description for GetProd
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class GetProd : System.Web.Services.WebService
    {
    
        public GetProd()
        {
    
            //Uncomment the following line if using designed components 
            //InitializeComponent(); 
        }
    
        [WebMethod]
       
        [System.Web.Script.Services.ScriptMethod]
    
        public static string[] GetProdDesSearch(string prefixText, int count)
        {
            try
            {
                TORDataContext dbac = new TORDataContext();
                return dbac.tblOnlineReportingCOMPLETEWeights
                    .Where(r => r.MemberId == "FM00012" && r.UnitDescription.StartsWith(prefixText))
                    .OrderBy(r => r.UnitDescription)
                    .Select(r => r.UnitDescription)
                    .Distinct()
                    .Take(count)
                    .ToArray();
    
            }
    
            catch
            {
            }
            return null;
        }
    }


    Now, I know the webmethod itself works as origianlly tested the functionality in a test solution...however, I can't get this version to work at all and it is driving me mad. I am assuming I have incorrectly set up the web service but I'm just a but stuck.

    If someone can point me in the right direction, I would really appreciated. Again, apologies for being thick.

  • Re: Autocomplete using webservice

    11-18-2009, 1:05 PM
    Answer
    • Contributor
      5,082 point Contributor
    • mrmercury
    • Member since 04-04-2006, 6:26 PM
    • Mexico City, Mexico
    • Posts 739

    Remove “static” from the WebMethod declaration, you only need it when using page methods.

    If this post helped you please remember to set it as Answer so it can help others.
  • Re: Autocomplete using webservice

    11-19-2009, 3:27 PM
    • Member
      point Member
    • MrDean
    • Member since 11-16-2009, 8:59 AM
    • Posts 30

    Top stuff Mr Mercury!

    Being a novice and all, I don't really understand the logic as to why that simple bloody word caused me so much head banging the other day! If you have the time, can you explain why that works in a page method and not through the webservice?

     

     

Page 1 of 1 (3 items)