[CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

  1. #1

    [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    hi,

    I failed to make use of the example that use generic-handler to load the store "custom search" with Paging<T>...

    I have WebService that Return Already Paged DataTable object from the BusinessLogicLayer but the store reader or something else doesn't understand the dataTable.

    as I said Paging Object make no sense since its make paging in the server side after fetching all records from DB "this is how i understood it so far". so how i can accomplish that...

    here is some code snippets:

    [WebMethod]
    public DataTable LoadComboBoxData(int start, int limit)
    {
    
        var db = new DBFactory("Currencies");
        var resultColumns = new List<string>();
        resultColumns.AddRange(new[] { "currencyId", "currencyName" });
    
        db.LoadListData(false, start, limit, resultColumns);
        //return db.TotalRecordCount;
        return db.DefaultView.Table;
    }
    the webservice return the recodes correctly but I need to return the TotalRecordCount beside the dataTable how I can do that??

    /// <summary>
    /// Creates Json reader for the store. It will updated, so that any type of reader could be used by store
    /// </summary>
    private void CreateJsonReader()
    {
        //Create reader for store
        JsonReader reader = new JsonReader();
        reader.IDProperty = this.ValueField;
        reader.Fields.Add(this.ValueField);
        reader.Fields.Add(this.DisplayField);
        if (this.HasAdditionalStoreColumns)
        {
            var fields = from column in this.AdditionalStoreColumnsArray
                         select new RecordField { Name = column };
            reader.Fields.AddRange(fields);
        }
        //reader.TotalProperty = "RecordCount";
        this.DataStore.Reader.Add(reader);
        //ToDo: Exception Management
    }
    
    this.DataStore.ID = string.Format("{0}_defaultStore", this.ID);
    this.DataStore.AutoLoad = this.AutoLoad;
    
    this.Controls.Add(this.DataStore);
    
    this.StoreID = this.DataStore.ID;
    this.LoadingText = "refreshing ...";
    
    //ToDo: Implement Sorting and Direction.
    //gridStore.RemotePaging = true;
    //gridStore.RemoteSort = true;
    
    this.DataStore.AutoLoadParams.Add(new Parameter("start", "0", ParameterMode.Raw));
    this.DataStore.AutoLoadParams.Add(new Parameter("limit", "5", ParameterMode.Raw));
    
    // Create Proxy
    HttpProxy storeProxy = new HttpProxy();
    storeProxy.Method = HttpMethod.POST;
    storeProxy.Url = "http://localhost/test/Services/GenericService.asmx/LoadComboBoxData";
    
    this.DataStore.Proxy.Add(storeProxy);
    it'll be nice if you could change/tune the planets example to full-fit my requirements.

    thanks,
  2. #2

    RE: [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    Edit:

    The problem I have that after the page render I get Error
    "Request Failure Status Code: 200" and inside the error window body the list of records of the DataTable populated.

  3. #3

    RE: [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    Hi,

    What kind of webservice do you use? XML or JSON?
  4. #4

    RE: [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    Hi,

    If you use XML WebService then you have to use XmlReader in the store
    Please see
    http://forums.ext.net/showthread.php...5848-16-1.aspx
    http://forums.ext.net/showthread.php...2123-16-1.aspx


    Also please see the following sample in the Examples Explorer (paging with XML web service)
    https://examples1.ext.net/#/GridPane...ML_WebService/


    Also I don't recommend to return DataSet/DataTable from web service because it is not efficient (poor performance, lage response (large amount of superfluous data) )


    Please see
    http://www.theserverside.net/tt/arti...Top5WSMistakes


    I recommend to use generic list as returned type
  5. #5

    RE: [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    Hi,

    as I said Paging Object make no sense since its make paging in the server side after fetching all records from DB "this is how i understood it so far"

    Paging object doesn't perform any paging. It returns paged data and total count only (it is wrapper (object container) for data and total count). We use generic list and perform paging in the memory for clearness and simplicity only. In real life you have to perform paging in the DB, return and convert paged data to any collection, after that return that collection in the Paging object (with total count number)
  6. #6

    RE: [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    Thanks for clearing the job of Paging object to me.

    now I want to make use of the JSON WebService but my Data Access Layer "My Generation/Doodads" return the data as DataTable I tried to convert the DataTable to List<DataRow> but the Json reader couldn't read the response.

    using a snippet from StackOverFlow

    //Webservic that shall return Json Object!!!
    [WebMethod]
    public List<DataRow> LoadComboBoxData(int start, int limit)
    {
    ...
    ...
    List<DataRow> list = db.DefaultView.Table.AsEnumerable().ToList();
    return list;
    }
    but I receive an http error 500 with the following error message!!

    {"Message":"A circular reference was detected while serializing an object of type \u0027System.Reflection.Module\u0027.","StackTrace":" at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
    please help me making a Json object out of DataTable that JsonReader can understand...I spent hours trying to serialize it myself using this guid:

    http://www.west-wind.com/weblog/posts/471835.aspx

    but nothing worked :(
  7. #7

    RE: [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    Hi,

    Try the following code
    [WebMethod]
    public System.Collections.Generic.List<System.Collections.Generic.Dictionary<string, object>> LoadComboBoxData(int start, int limit)
    {
        System.Data.DataTable dt = db.DefaultView.Table;
        System.Collections.Generic.List<System.Collections.Generic.Dictionary<string, object>> list = new System.Collections.Generic.List<System.Collections.Generic.Dictionary<string, object>>();
        foreach (System.Data.DataRow row in dt.Rows)
        {
            System.Collections.Generic.Dictionary<string, object> rowDic = new System.Collections.Generic.Dictionary<string, object>();
            foreach (System.Data.DataColumn column in row.Table.Columns)
            {
                rowDic.Add(column.ColumnName, row[column]);
            }
            list.Add(rowDic);
        }
        
        return list;
    }
  8. #8

    RE: [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    hi,

    it didn't work, it gives me this error:

    {"Message":"Object reference not set to an instance of an 
    object.","StackTrace":"   at 
    MyGeneration.dOOdads.BusinessEntity.Setstring(String columnName, String 
    data) in 
    E:\\WebClouders\\MyGeneration.dOOdads_2005\\BusinessEntity.cs:line 
    1786\r\n   at 
    WebClouders.Media.DataAccess._currencies.set_CurrencyName(String value) 
    in 
    E:\\WebClouders\\WebClouders.Media\\WebClouders.Media.DataAccess\\currencies.cs:line
     533\r\n   at 
    WebClouders.Media.UserServices.Services.GenericService.LoadComboBoxData(Int32
     start, Int32 limit) in 
    E:\\WebClouders\\WebClouders.Media\\WebClouders.Media.UserServices\\Services\\GenericService.asmx.cs:line
     45","ExceptionType":"System.NullReferenceException"}
    the only method worked so far is by creating dummy class "data container" that have 'properties names = column names', 'properties values = column values' just like the planet class in custom search example...but as i said it will be very difficult to change my DAL and make data container for every data object i wanna loaded through json webservice....

    can you do something to let the json reader understand a serialized json string returned from the webservice???
  9. #9

    RE: [CLOSED] [1.0] Store of WebService HttpProxy with DataTable Paging

    hi,

    I'm super sorry, your method worked just like charm but because i had some trash code in the body of the webservice it was generating the previous error.

    with little extend your method can work with Paging object also

    [WebMethod]
    public Paging<Dictionary<string, object>> LoadComboBoxData(int start, int limit)
    {
        System.Data.DataTable dt = db.DefaultView.Table;
        List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
        foreach (System.Data.DataRow row in dt.Rows)
        {
            Dictionary<string, object> rowDic = new Dictionary<string, object>();
            foreach (System.Data.DataColumn column in row.Table.Columns)
            {
                rowDic.Add(column.ColumnName, row[column]);
            }
            list.Add(rowDic);
        }
        
        return new Paging<Dictionary<string, object>>(list.AsEnumerable(), db.RecordCount);
    }
    so marked as solved and thanks a lot!
  10. #10
    thanks great :o

Similar Threads

  1. Replies: 1
    Last Post: Jun 26, 2012, 1:40 PM
  2. Replies: 0
    Last Post: Jul 07, 2011, 8:19 PM
  3. [FIXED] [RC2] HttpProxy paging with json
    By PetrSnobelt in forum Bugs
    Replies: 7
    Last Post: Jun 10, 2011, 12:08 PM
  4. Replies: 5
    Last Post: Jul 23, 2010, 8:52 AM
  5. Replies: 2
    Last Post: Nov 17, 2009, 1:26 PM

Posting Permissions