Error when databinding to webservice/wcf

6 posts, 0 answers
  1. Klestrup
    Klestrup avatar
    1 posts
    Member since:
    Apr 2007

    Posted 02 Aug 2012 Link to this post

    Hi guys, I cant get the databinding to work, either on webservice or WCF. I have tried binding to both local webservice in same project and deployed webservice on remote server (both functioning), but when querying for data all I get is: "The server method 'GetKeywordList' failed"
    (GetKeywordList is the name of the webmethod / operationcontract)

    Any good advice?
    Best regards,
    Kim
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 06 Aug 2012 Link to this post

    Hi Klestrup,

    Thank you for your feedback.

    I am sending you a sample project where RadAutoCompleteBox is populated via web services.
    Please download it, add references to Telerik assemblies and use the attached Northwind database to test the control binding.
    Feel free to contact me if you have additional questions.


    All the best,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Darren
    Darren avatar
    14 posts
    Member since:
    Sep 2012

    Posted 20 Sep 2012 Link to this post

    This is great sample code. I see the web service returns an AutoCompleteBoxData node which has a Text and a Value property. I'm trying to achieve something like this (http://demos.telerik.com/aspnet-ajax/autocompletebox/examples/templates/defaultcs.aspx ) where templates are used. Using templates I need to return more than just test/value. I need to return about 5 values. How could I modify this sample to accomplish this?

    Thanks!
    [WebMethod]
    public AutoCompleteBoxData GetCompanyNames(RadAutoCompleteContext context)
    {
     
        string sql = "SELECT  * from Customers WHERE CompanyName LIKE '" + context.Text + "%'";
        SqlDataAdapter adapter = new SqlDataAdapter(sql,
            ConfigurationManager.ConnectionStrings["NorthwindConnectionString1"].ConnectionString);
        DataTable data = new DataTable();
        adapter.Fill(data);
        List<AutoCompleteBoxItemData> result = new List<AutoCompleteBoxItemData>();
     
        foreach (DataRow row in data.Rows)
        {
            AutoCompleteBoxItemData childNode = new AutoCompleteBoxItemData();
            childNode.Text = row["CompanyName"].ToString();
            childNode.Value = row["CustomerID"].ToString();
            result.Add(childNode);
        }
     
        AutoCompleteBoxData res = new AutoCompleteBoxData();
        res.Items = result.ToArray();
     
        return res;
    }

  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 21 Sep 2012 Link to this post

    Hi Darren,

    Please take a look at the GetChildren method implementation in the demo code.
    You can add Attributes to every AutoCompleteBoxItemData instance:
    [WebMethod]
        public static AutoCompleteBoxData GetChildren(object context)
        {
            string searchString = ((Dictionary<string, object>)context)["Text"].ToString();
            DataTable data = GetChildNodes(searchString);
            List<AutoCompleteBoxItemData> result = new List<AutoCompleteBoxItemData>();
     
            foreach (DataRow row in data.Rows)
            {
                AutoCompleteBoxItemData childNode = new AutoCompleteBoxItemData();
                childNode.Text = row["ContactName"].ToString();
                childNode.Attributes.Add("ContactTitle", row["ContactTitle"].ToString());
                childNode.Attributes.Add("City", row["City"].ToString());
                childNode.Attributes.Add("Country", row["Country"].ToString());
                childNode.Attributes.Add("Phone", row["Phone"].ToString());
                childNode.Attributes.Add("Photo", System.Web.VirtualPathUtility.ToAbsolute("~/Img/Northwind/Customers/" + row["CustomerID"].ToString() + ".jpg"));
                result.Add(childNode);
            }
     
            AutoCompleteBoxData res = new AutoCompleteBoxData();
            res.Items = result.ToArray();
     
            return res;
        }

    Then in markup you can implement a Client-side template.

    All the best,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Vinu
    Vinu avatar
    1 posts
    Member since:
    Dec 2012

    Posted 10 Jan 2013 Link to this post

    I am trying to bind a list of 3000 strings to the RadAutoCompleteBox using Web Service. I have used the sample applications attached in this thread but it keeps throwing an Error saying "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property"

    Here is my code:
    ASPX:
    <telerik:RadAutoCompleteBox runat="server" ID="radAcBxSearch">
                                        <WebServiceSettings Path="WebService_TEST.asmx" Method="GetList" />
                                    </telerik:RadAutoCompleteBox>


    WebService_TEST.ASMX
    [WebMethod]
            public AutoCompleteBoxData GetList()
            {
               
                    var query = ProdDbContext.Select(x => x.Name).ToList();

                    List<AutoCompleteBoxItemData> result = new List<AutoCompleteBoxItemData>();
                    AutoCompleteBoxData dropDownData = new AutoCompleteBoxData();

                    result = new List<AutoCompleteBoxItemData>();

                    foreach (string str in query)
                    {
                        AutoCompleteBoxItemData itemData = new AutoCompleteBoxItemData();
                        itemData.Text = str;
                        itemData.Value = str;

                        result.Add(itemData);
                    }

                    dropDownData.Items = result.ToArray();
                    return dropDownData;
                }
            }
  7. Cat Cheshire
    Cat Cheshire avatar
    128 posts
    Member since:
    Jun 2010
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017