Hi,
We are designing an application using ASP MVC , Entity Framework and Kendo UI.
The client now has a requirement to abstract the datalayer(Entity Framework) using plane WCF service(not WCF
Dataservice as we need tcp).
So basically now our MVC controller will internally call the WCF service to get the data.
But we are not clear how to apply filtering , paging etc for the grid using this structure as there are no server wrapper available for WCF.
Here i have 2 questions.
1. Is there anything similar to DataSourceResult in wcf. i saw an example http://www.kendoui.com/code-library/web/grid/grid-wcf---crud.aspx , but here the code is placed in AppCode. Is there any implementation example where I have a seprate wcf service and its methods taking a parameter DataSourceResult?
2. Or is there a way that I can pass the DataSourceResult from my MVC controller to a WCF plane service.?
Regards
Ramesh
10 Answers, 1 is accepted
We do not have specific API for a WCF servcice but you could use the ToDataSourceResult method to perform the queries. I can suggest to pass the sort, filter, group, etc. descriptors as strings(as they are received in the controller without the DataSourceRequestAttribute) to the service and then use the approach from this code-library to parse them e.g.
public
DataSourceRequest ParseRequest(
int
? page,
int
? pageSize,
string
sort,
string
group,
string
filter,
string
aggregates)
{
DataSourceRequest request =
new
DataSourceRequest();
if
(page.HasValue)
{
request.Page = page.Value;
}
if
(pageSize.HasValue)
{
request.PageSize = pageSize.Value;
}
if
(!
string
.IsNullOrEmpty(sort))
{
request.Sorts = GridDescriptorSerializer.Deserialize<SortDescriptor>(sort);
}
if
(!
string
.IsNullOrEmpty(filter))
{
request.Filters = FilterDescriptorFactory.Create(filter);
}
if
(!
string
.IsNullOrEmpty(group))
{
request.Groups = GridDescriptorSerializer.Deserialize<GroupDescriptor>(group);
}
if
(!
string
.IsNullOrEmpty(aggregates))
{
request.Aggregates = GridDescriptorSerializer.Deserialize<AggregateDescriptor>(aggregates);
}
return
request;
}
Regards,
Daniel
the Telerik team

That example code helps. I'm able to get data source request data to WCF service from my MVC controller.
But I'm having issues with returning data source result from WCF service back to MVC controller.
How can i get the DataSourceResult from WCF service to MVC controller?
Thanks

Let me know if that's the right way or Telerik recommends another way.
Thanks
We are not sure how your implementation looks like. However you can just call your service from the action method and return its result.
public ActionResult Read([DataSourceRequest]DataSourceRequest request)
{
return Json(myService.Read(request));
}
The service method should in turn call the ToDataSourceResult extension method in order to convert your data to a DataSourceResult object given the current DataSourceRequest.
Regards,
Atanas Korchev
Telerik

I tried to pass DataSourceRequest and return DataSourceResult from WCF. I got errors that "those are not serializable".
Please see the attached project for how i've implemented KendoUI in 3 tier ( where controller calling WCF service to get the data)
Looking forward to your feedback and thanks for your help
-James
PS - I'm using the Person table from AdventureWorks database
CREATE TABLE [Person].[Person](
[BusinessEntityID] [int] NOT NULL,
[PersonType] [nchar](2) NOT NULL,
[NameStyle] [dbo].[NameStyle] NOT NULL,
[Title] [nvarchar](8) NULL,
[FirstName] [dbo].[Name] NOT NULL,
[MiddleName] [dbo].[Name] NULL,
[LastName] [dbo].[Name] NOT NULL,
[Suffix] [nvarchar](10) NULL,
[EmailPromotion] [int] NOT NULL,
[AdditionalContactInfo] [xml] NULL,
[Demographics] [xml] NULL,
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ModifiedDate] [datetime] NOT NULL
)
Thank you for providing a sample project. However it seems to run as expected when I test it. I couldn't get an error that an object isn't serializable. The only modification I did was to use LocalDB instead of SQL.
I used OpenAccess 2013.3.1211.3 and Kendo UI 2013.3.1119.440. Here is a screencast that shows my experience: http://screencast.com/t/qFb3cWKSYV
In any case the problem with serialization could happen due to circular references. You can try the workaround from this help topic.
Regards,
Atanas Korchev
Telerik

The code i sent you is my custom model binder (MyDataSourceRequestBinder and MyDataSourceRequest class) that passes the grid values to controller action.
And then i have a my custom data contract called "MyDataSourceRequest" in WCF service to pass the grid parameters to WCF and return json string. so its all working without errors.
To me , from you reply here is link , it sounded like i can pass the DataSourceRequest telerik class to WCF service and return DataSourceResult from WCF without issues. It made me think that i didn't need to implement my custom datacontract , model binder and all that.
http://www.kendoui.com/forums/kendo-ui-complete-for-asp-net-mvc/grid/kendo-mvc-and-wcf.aspx#UvFTt9Xz60G-fQ_dy7WT6g
Can you change the WCF service input paramet from MyDataSourceRequest to DataSourceRequest and return value from string to DataSourceResult (both telerik's classes)? when you change it, its going to throw errors.
I would like telerik team to review my 3 tier implementation and make sure its meets the telerik's guidelines.
Thanks
While you can pass the DataSourceRequest just fine you can't make a WCF service return a DataSourceResult because it isn't decorated with the DataContract attribute. The solution is to either serialize the DataSourceResult as a JSON string (as you have found out) or create a custom class which has the same properties as DataSourceResult.
I have updated your solution to demonstrate the second approach.
To summarize you can use the DataSourceRequest from WCF but you cannot return DataSourceResult.
Regards,
Atanas Korchev
Telerik

{"Type 'Kendo.Mvc.FilterDescriptor' with data contract name 'FilterDescriptor: http: //schemas.datacontract.org/2004/07/Kendo.Mvc'
It is not expected. Consider using DataContractResolver or add some types not known statically to the list of known types -
for example, using KnownTypeAttribute attribute or adding them to the list
of known types transmitted to DataContractSerializer. "}
Can you help me ?
Did you try passing the state parameters as strings and then deserialize them in the service? The approach is demonstrated in the project that James attached to the thread. The custom model binder should not be needed in this scenario. The MVC default model binder should be able to bind the state strings that are sent to the controller.
Regards,
Daniel
Telerik