This is a migrated thread and some comments may be shown as answers.

[Solved] RadGrid.GetBindingData Error

3 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jacek Dudziak
Top achievements
Rank 1
Jacek Dudziak asked on 26 Nov 2009, 12:16 AM
I am using Q3 2009 ASP.Net AJAX controls. I am trying to mimic sample with Grid, client site binding and Order/Details navigation.
I have created my own WCF Service based on GridMasterDetailService.cs from samples.

My Model is inside namespace like: AAA.BBB.CCC.Model and has been generated as MyDBNameDataContext class.
The service uses slightly different namespace: AAA.BBB.CCC.MyService. Inside it I am making call like:

RadGrid.GetBindingData("AAA.BBB.CCC.Model.MyDBNameDataContext", ....)
 
However any time I call it it errors out with "Could not find the type specified in the ContextTypeName property of LinqDataSource ''."

- I have tried all combinations of naming the data context by cutting out all sub-names from the full namespace
- I have compiled and run the sevice with "new MyDBNameDataContext()" just before the GetBindingData call - it works.

Does anybody know what I am missing? Is there any special keyword that GetBindingData requires?

On more thing: my WCF service is not hosted inside IIS. I have noticed that the inner exception comes from System.Web library. So additional question is: can the RadGrid.GetBindingData be hosted outside IIS?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 01 Dec 2009, 09:56 AM
Hi Jacek,

The DataContext class whose type you provide should be properly initialized inside the default constructor, as RadGrid.GetBindingData() instantiates a GridLinqDataSource object passing to its constructor the type you have provided. Other that that, everything should be working OK. Here is the method definition:

public static GridBindingData GetBindingData(string contextTypeName, string tableName, int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
        {
            GridLinqDataSource dataSource = new GridLinqDataSource(contextTypeName, tableName, "", startRowIndex, maximumRows, sortExpression, filterExpression);
            System.Web.UI.Pair result = dataSource.GetData();
 
            return new GridBindingData(((IEnumerable)result.First).OfType<object>().ToList(), (int)result.Second);
        }
 
        public static GridBindingData GetBindingData(string contextTypeName, string tableName, string select, int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
        {
            GridLinqDataSource dataSource = new GridLinqDataSource(contextTypeName, tableName, select, startRowIndex, maximumRows, sortExpression, filterExpression);
            System.Web.UI.Pair result = dataSource.GetData();
 
            return new GridBindingData(((IEnumerable)result.First).OfType<object>().ToList(), (int)result.Second);
        }


As for the second question, what do you mean by "my WCF service is not hosted inside IIS"? The Telerik example demonstrates a WCF service that needs IIS to run. Could you, please, clarify?

Greetings,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jacek Dudziak
Top achievements
Rank 1
answered on 01 Dec 2009, 05:19 PM
Thanks for your answer. It will help me further troubleshooting my problem.

Hosting options of WCF are explained here: http://msdn.microsoft.com/en-us/library/ms730158.aspx
To summarize it, WCF services can be hosted in three types of environments: IIS, Windows Process Activation Service (WAS) and Self-hosted. The beauty of it is that WCF implementation is independent from host it is using. Which means you can implement service once and then create multiple hosts for it and deploy it in different environments. I my case I am using Self-Hosted environment in a form of Windows Service. I have also tried to run it in console application.

My guess is that somewhere inside GetBindingData/GridLinqDataSource you are using libraries which exist only in IIS environment, and by doing that, you have limited WCF functionality to just one host type. If that is the case, having better documentation around GridBindingData would help, so other grid users like myself could attempt implement it without using your RadGrid.GetBindingData method.

If my guess is true, there is a big chance that you have made the same assumption inside classes that that generate data for other controls. So you may have a look at it and consider fixing it in future releases.
0
Veli
Telerik team
answered on 02 Dec 2009, 12:22 PM
Hello Jacek,

Thank you for the detailed explanation of the WCF hosting options and the approach you have taken. For your reference, here is the implementation of the GridBindingData and GridLinqDataSource  classes in Telerik.Web.UI.dll:

    public class GridBindingData
    {
        int _count;
        List<object> _data;
 
        public GridBindingData()
        {
            //
        }
 
        public GridBindingData(List<object> data, int count)
        {
            _count = count;
            _data = data;
        }
 
        public int Count
        {
            get
            {
                return _count;
            }
            set
            {
                _count = value;
            }
        }
 
        public List<object> Data
        {
            get
            {
                return _data;
            }
            set
            {
                _data = value;
            }
        }
    }
 
#if ASPNET35
    public class GridLinqDataSource : LinqDataSource
    {
        int _startRowIndex;
        int _maximumRows;
        string _sortExpression;
        string _filterExpression;
    /*
        public GridLinqDataSource(Telerik.Web.UI.RadGrid.GridBindingDataParameters args)
        {
            _startRowIndex = args.StartRowIndex;
            _maximumRows = args.MaximumRows;
            _sortExpression = args.OrderBy;
            _filterExpression = args.Where;
            ContextTypeName = args.ContextTypeName;
            TableName = args.TableName;
            Select = args.Select;
        }
    */
        public GridLinqDataSource(string contextTypeName, string tableName, string select, int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
        {
            _startRowIndex = startRowIndex;
            _maximumRows = maximumRows;
            _sortExpression = sortExpression;
            _filterExpression = filterExpression;
            ContextTypeName = contextTypeName;
            TableName = tableName;
            Select = select;
        }
         
        public System.Web.UI.Pair GetData()
        {
            System.Web.UI.Pair pair = new System.Web.UI.Pair();
             
            LinqDataSourceView view = (LinqDataSourceView)GetView("DefaultView");
            System.Web.UI.DataSourceSelectArguments args = new System.Web.UI.DataSourceSelectArguments();
            args.MaximumRows = _maximumRows;
            args.StartRowIndex = _startRowIndex;
            args.SortExpression = _sortExpression;
            args.RetrieveTotalRowCount = true;
 
            if (!String.IsNullOrEmpty(_filterExpression))
            {
                view.Where = _filterExpression;
            }
 
            pair.First = view.Select(args);
 
            pair.Second = args.TotalRowCount;
 
            return pair;
        }
    }
#endif

You can even bypass using the above two classes and implement your own classes that will help you return data from your WCF service. Unfortunately I do not have any observations as to whether the above code would work outside of IIS, but you can see nothing fancy happens here.

Chances are you cannot even access WCF service hosted as a Windows Service from a Web Application. Have you tried that without RadControls? Can you, please, share with us the exact steps of accessing a WCF service hosted outside of IIS from a web application running in IIS? No RadControls involved.

Greetings,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Jacek Dudziak
Top achievements
Rank 1
Answers by
Veli
Telerik team
Jacek Dudziak
Top achievements
Rank 1
Share this question
or