locked
autocomplete extender not finding service method RRS feed

  • Question

  • User348142989 posted

    HI

    Moving from VB to C# (still learning).  I have installed Ajax control toolkit and tested it with an accordion.  Thus I know the tool kit is installed correctly.

    Have added a Webservice.asmx file and added reference to the service.  Added a button and text box and with code behind can reach the webservice method which returns a value (just test junk for the moment)

    page markup for test button

    <div>
    <asp:Button ID="Button1" runat="server"
    Text="Button"
    OnClick="Button1_Click"
    style="height: 26px" />
    <br />
    <asp:Label ID="Label1" runat="server"
    Text="Label">
    </asp:Label>
    </div>

    code behind for button

    protected void Button1_Click(object sender, EventArgs e)
    {
    WebService webService = new WebService();
    List<int> lstIntegers = new List<int> { 5, 6, 7 };
    Label1.Text = "Output of WebService: " + webService.Add(lstIntegers).ToString();
    }

    and finally web method which works.

    [WebMethod]
    public int Add(List<int> listInt)
    {
    //https://www.c-sharpcorner.com/article/how-to-create-a-web-service-project-in-net-using-visual-studio/
    int result = 0;
    for (int i = 0; i < listInt.Count; i++)
    {
    result = result + listInt[i];
    }
    return result;
    }

    I run into troubles when I add a text box and and associated autocompleteextender.  (this works ok when I program using VB)

    page markup for text box and autocompleteextender

    <asp:TextBox ID="ImageNameSearchTextBox" runat="server"
    style="width:100%">
    </asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender ID="ImageNameSearchTextBox_AutoCompleteExtender" runat="server"
    BehaviorID="ImageNameSearchTextBox_AutoCompleteExtender"
    DelimiterCharacters=""
    ServicePath="~/WebService.asmx"
    ServiceMethod="Get_Image_Names"
    CompletionInterval="10"
    completionsetcount="10"
    enablecaching="true"
    MinimumPrefixLength="1"
    TargetControlID="ImageNameSearchTextBox">
    </ajaxToolkit:AutoCompleteExtender>

    and associated web method. which should return a list of letters.

    public List<string> Get_Image_Names(string prefixText, int count)
    {
    //https://www.aspdotnet-suresh.com/2011/03/how-to-implement-auto-complete-textbox.html
    List<string> my_list = new List<string>();
    my_list.Add("ab");
    my_list.Add("ak");
    my_list.Add("kl");
    my_list.Add("kk");
    return my_list;
    }

    What am I missing?  

    Thanks in advance for any help!

    Monday, July 8, 2019 6:55 PM

Answers

  • User665608656 posted

    Hi TiredOldCat,

    According to the information you provided, I found that all of these were all right.

    Based on the information in your picture, you created the page in the MVC project. ASP.NET MVC routing may parse the call of asmx as the path of MVC, so this method can not be successfully invoked.

    I recommend that you add the following statement to the RouteConfig.cs file under the folder App_Start:

    public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
    
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

    If this also cannot solve your issue, please provide all the content of RouteConfig.cs file in your mvc application.

    Best Regards,

    YongQing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 15, 2019 8:03 AM

All replies

  • User665608656 posted

    Hi TiredOldCat,

    According to your description, if the ajaxtoolkit control wants to invoke methods in webservice.asmx,you need to enable properties on the asmx page as follow:

    [System. Web. Script. Services. ScriptService]

    You can see that on your webservice.asmx page there is a line of commented out statements that you need to enable the properties, cancel its comment, then ajaxtoolkit control can trigger the webmethod of the asmx page.

    For more details , you could refer to the following code in asmx page:

     /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 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 WebService : System.Web.Services.WebService
        {
            [WebMethod]
            public List<string> Get_Image_Names(string prefixText, int count)
            {
                List<string> my_list = new List<string>();
                my_list.Add("ab");
                my_list.Add("ak");
                my_list.Add("kl");
                my_list.Add("kk");
                return my_list;
            }
        }

    The result of this work demo:

    Best Regards,

    YongQing.

    Tuesday, July 9, 2019 3:05 AM
  • User348142989 posted

    Hi YongQing

    Here is the code for my .asmx page.  As you can see, the  [System.Web.Script.Services.ScriptService] is uncommented.

    I copied your code just to ensure something had not crept into the file.   

    Unfortunately, the autocomplete still does not connect.

    namespace _2019_Pictures_C_1
    {
        /// https://www.c-sharpcorner.com/members/archana-saini
        /// 
        /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 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 WebService : System.Web.Services.WebService
        {
            public List<string> Get_Image_Names(string prefixText, int count)
            {
                //https://www.aspdotnet-suresh.com/2011/03/how-to-implement-auto-complete-textbox.html
                List<string> my_list = new List<string>();
                my_list.Add("ab");
                my_list.Add("ak");
                my_list.Add("kl");
                my_list.Add("kk");
                return my_list;
            }
     
     
    My .aspx page is in a subdirectory.  My .asmx file is in the root directory.  But I think that this should not matter.
     
    Any suggestions where else I might look?
     
    Thanks for your help.

    Tuesday, July 9, 2019 5:50 PM
  • User665608656 posted

    Hi TiredOldCat,

    According to your description, your .aspx page is in the subdirectory folder, and your .asmx file is in the root folder.

    You need to change the ServicePath property of the AutoCompleteExtender control to ".. /WebService.asmx".

    You can refer to this link: Server.MapPath(“.”), Server.MapPath(“~”), Server.MapPath(@“\”), Server.MapPath(“/”). What is the difference?

    Best Regards,

    YongQing.

    Wednesday, July 10, 2019 1:32 AM
  • User348142989 posted

    HI Again

    Here is my markup for the text box and the autocomplete extender.  The aspx. file lives in a subdirectory.

    <asp:TextBox ID="ImageNameSearchTextBox" runat="server"
    style="width:100%">
    </asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender ID="ImageNameSearchTextBox_AutoCompleteExtender" runat="server"
    BehaviorID="ImageNameSearchTextBox_AutoCompleteExtender"
    DelimiterCharacters=""
    ServicePath="../WebService.asmx"
    ServiceMethod="Get_Image_Names"
    CompletionInterval="10"
    completionsetcount="10"
    enablecaching="true"
    MinimumPrefixLength="1"
    TargetControlID="ImageNameSearchTextBox">
    </ajaxToolkit:AutoCompleteExtender>

    Here is my .asmx file (WebService.asmx) which lives in the root directory.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;


    namespace _2019_Pictures_C_1
    {
        /// https://www.c-sharpcorner.com/members/archana-saini
        /// 
        /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 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 WebService : System.Web.Services.WebService
        {
            [WebMethod]
            public List<string> Get_Image_Names(string prefixText, int count)
            {
                //https://www.aspdotnet-suresh.com/2011/03/how-to-implement-auto-complete-textbox.html
                List<string> my_list = new List<string>();
                my_list.Add("ab");
                my_list.Add("ak");
                my_list.Add("kl");
                my_list.Add("kk");
                return my_list;
            }

    The extender is still not reaching the web method.  Any other suggestions?

    Thanks and have a nice day.

    Wednesday, July 10, 2019 5:16 PM
  • User475983607 posted

    Use the browser's dev tools (F12) to get any error messages.  Dev tools has a console and network trace which a very helpful.

    Wednesday, July 10, 2019 5:24 PM
  • User665608656 posted

    Hi TiredOldCat,

    Did you solve the issue?I tested with the complete code you provided once again , and everything worked.

    As suggested by mgebhard, you need to use the F12 tool to check in console whether there is an error message, if there is, you can tell us the information, which will help us solve it more easily.

    I suggest you check whether your ajaxtoolkit reference tool is working properly and provide us with detailed information about the location of your two files.

    Best Regards,

    YongQing.

    Thursday, July 11, 2019 5:51 AM
  • User348142989 posted

    Hi

    Thanks for the suggestions.  Unfortunately, I have other issues to solve for a day or two and then I will try to find the error message or code.  Have a nice day.

    Thursday, July 11, 2019 11:23 AM
  • User348142989 posted

    Hi YongQing

    removed all markup from .aspx page except text box and autocomplete extender.  Used F12 to find error listing (as follows)

    MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1 POST https://localhost:44302/WebService.asmx/Get_Image_Names 404
    executeRequest @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    executeRequest @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    invoke @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    Sys.Net.WebServiceProxy.invoke @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    _onTimerTick @ ScriptResource.axd?d=bNiRhTx965PPeR3Igr1Rytyn72m7eUA1SEoJS6w3XKiXtjHCeTYQObIMClHooD9Em4ZvAx7cJzKH10FQEIP8TjvUyaGsqjjkT1TUDHklg0QRFVS8sr2JFjE-3BA6i7GZ0&t=ffffffffb56adc1f:709
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    _timerCallback @ ScriptResource.axd?d=iC2sD0Al8A6ZX4AVmUco0RDYnttWfU0wbRhdwpLUFKvrpMyegJdvBe6EvaNqxmLdzOIXGA1vDXvD8YDG6-jbs-uYhnNV1HYAtYCOOKxx-zoFMmlQ5sDdG1_4SPjGoGRZ0&t=ffffffffb56adc1f:76
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    setInterval (async)
    _startTimer @ ScriptResource.axd?d=iC2sD0Al8A6ZX4AVmUco0RDYnttWfU0wbRhdwpLUFKvrpMyegJdvBe6EvaNqxmLdzOIXGA1vDXvD8YDG6-jbs-uYhnNV1HYAtYCOOKxx-zoFMmlQ5sDdG1_4SPjGoGRZ0&t=ffffffffb56adc1f:80
    set_enabled @ ScriptResource.axd?d=iC2sD0Al8A6ZX4AVmUco0RDYnttWfU0wbRhdwpLUFKvrpMyegJdvBe6EvaNqxmLdzOIXGA1vDXvD8YDG6-jbs-uYhnNV1HYAtYCOOKxx-zoFMmlQ5sDdG1_4SPjGoGRZ0&t=ffffffffb56adc1f:43
    _onKeyDown @ ScriptResource.axd?d=bNiRhTx965PPeR3Igr1Rytyn72m7eUA1SEoJS6w3XKiXtjHCeTYQObIMClHooD9Em4ZvAx7cJzKH10FQEIP8TjvUyaGsqjjkT1TUDHklg0QRFVS8sr2JFjE-3BA6i7GZ0&t=ffffffffb56adc1f:604
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    f @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1 Uncaught TypeError: Cannot read property 'webServiceFailedNoMsg' of undefined
    at Array.it (MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1)
    at MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    at Sys.Net.WebRequest.completed (MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1)
    at XMLHttpRequest._onReadyStateChange (MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1)
    it @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    completed @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    _onReadyStateChange @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    XMLHttpRequest.send (async)
    executeRequest @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    executeRequest @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    invoke @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    Sys.Net.WebServiceProxy.invoke @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    _onTimerTick @ ScriptResource.axd?d=bNiRhTx965PPeR3Igr1Rytyn72m7eUA1SEoJS6w3XKiXtjHCeTYQObIMClHooD9Em4ZvAx7cJzKH10FQEIP8TjvUyaGsqjjkT1TUDHklg0QRFVS8sr2JFjE-3BA6i7GZ0&t=ffffffffb56adc1f:709
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    _timerCallback @ ScriptResource.axd?d=iC2sD0Al8A6ZX4AVmUco0RDYnttWfU0wbRhdwpLUFKvrpMyegJdvBe6EvaNqxmLdzOIXGA1vDXvD8YDG6-jbs-uYhnNV1HYAtYCOOKxx-zoFMmlQ5sDdG1_4SPjGoGRZ0&t=ffffffffb56adc1f:76
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    setInterval (async)
    _startTimer @ ScriptResource.axd?d=iC2sD0Al8A6ZX4AVmUco0RDYnttWfU0wbRhdwpLUFKvrpMyegJdvBe6EvaNqxmLdzOIXGA1vDXvD8YDG6-jbs-uYhnNV1HYAtYCOOKxx-zoFMmlQ5sDdG1_4SPjGoGRZ0&t=ffffffffb56adc1f:80
    set_enabled @ ScriptResource.axd?d=iC2sD0Al8A6ZX4AVmUco0RDYnttWfU0wbRhdwpLUFKvrpMyegJdvBe6EvaNqxmLdzOIXGA1vDXvD8YDG6-jbs-uYhnNV1HYAtYCOOKxx-zoFMmlQ5sDdG1_4SPjGoGRZ0&t=ffffffffb56adc1f:43
    _onKeyDown @ ScriptResource.axd?d=bNiRhTx965PPeR3Igr1Rytyn72m7eUA1SEoJS6w3XKiXtjHCeTYQObIMClHooD9Em4ZvAx7cJzKH10FQEIP8TjvUyaGsqjjkT1TUDHklg0QRFVS8sr2JFjE-3BA6i7GZ0&t=ffffffffb56adc1f:604
    (anonymous) @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1
    f @ MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1

    Unfortunately, I do not have enough knowledge to figure out what this is telling me.  Looking forward to your reply and thanks.

    Thursday, July 11, 2019 7:26 PM
  • User665608656 posted

    Hi TiredOldCat,

    According to your error prompt, 404 is a common error on the client side, which means that the page you requested does not exist.

    There are many possibilities, but the most likely one is your URL orientation error.

    I suggest that you give me a screenshot of the relationship between the location of your file and make sure that your service path is correct.

    Here are some common solutions to 404 errors, you can refer to: https://www.lifewire.com/404-not-found-error-explained-2622936

    Below is my file location diagram with my code,you can compare yours, hope it can help you.

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm_0711_2157533.aspx.cs" Inherits="WebApplication_July.Case_two.WebForm_0711_2157533" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
             <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:TextBox ID="ImageNameSearchTextBox" runat="server"
                Style="width: 100%">
            </asp:TextBox>
            <ajaxtoolkit:autocompleteextender id="ImageNameSearchTextBox_AutoCompleteExtender" runat="server"
                behaviorid="ImageNameSearchTextBox_AutoCompleteExtender"
                delimitercharacters=""
                servicepath="../WebService.asmx"
                servicemethod="Get_Image_Names"
                completioninterval="10"
                completionsetcount="10"
                enablecaching="true"
                minimumprefixlength="1"
                targetcontrolid="ImageNameSearchTextBox">
    </ajaxtoolkit:autocompleteextender>
        </form>
    </body>
    </html>

    Best Regards,

    YongQing.

    Friday, July 12, 2019 1:45 AM
  • User348142989 posted

    HI

    I would like to insert an image but the editor will not let me.

    Thanks.

    Saturday, July 13, 2019 11:54 AM
  • User348142989 posted

    Hi YongQing

    I looked at old web site (using VB) and for Ajax to work, I needed to add stuff to the web config file.  Would there be updates to the web config required. 

    I am using VS 2019 v16.1.6 with Ajax control toolkit v19.1  HTML5

    Finally had time to figure out how to add an image.  Hope this works.  https://imageshack.com/i/pnxT7xMYj 

    img src="https://imageshack.com/i/pnxT7xMYj" />
    Sunday, July 14, 2019 12:30 PM
  • User665608656 posted

    Hi TiredOldCat,

    According to the information you provided, I found that all of these were all right.

    Based on the information in your picture, you created the page in the MVC project. ASP.NET MVC routing may parse the call of asmx as the path of MVC, so this method can not be successfully invoked.

    I recommend that you add the following statement to the RouteConfig.cs file under the folder App_Start:

    public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
    
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

    If this also cannot solve your issue, please provide all the content of RouteConfig.cs file in your mvc application.

    Best Regards,

    YongQing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 15, 2019 8:03 AM
  • User348142989 posted

    Hi YongQing

    Many thanks for your solution.  This worked.

    I created another project and tested that scenario which worked as well.

    Thanks and have a nice day

    Very happy TiredOldCat

     

    Monday, July 15, 2019 11:50 AM