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

Kendo MVC and WCF

10 Answers 409 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jackie
Top achievements
Rank 1
jackie asked on 10 Feb 2013, 12:46 PM

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

Sort by
0
Accepted
Daniel
Telerik team
answered on 13 Feb 2013, 08:26 AM
Hello Ramesh,

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;
}
Regarding the crud code-library - the same approach cannot be used with the wrappers because the format of the send parameters is diffirent. It is possible to use it with the JavaScript initialization. The same approach should work when the code is not placed in the App_Code folder.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
James
Top achievements
Rank 1
answered on 26 Dec 2013, 04:44 PM
Hi Daniel, 
  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
0
James
Top achievements
Rank 1
answered on 26 Dec 2013, 06:17 PM
I thought of converting DataSourceResult to JSON string in WCF and return to MVC Controller. 
Let me know if that's the right way or Telerik recommends another way.

Thanks
0
Atanas Korchev
Telerik team
answered on 27 Dec 2013, 10:00 AM
Hi James,

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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
James
Top achievements
Rank 1
answered on 27 Dec 2013, 08:23 PM
Hi Atanas, 
  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
)
0
Atanas Korchev
Telerik team
answered on 30 Dec 2013, 09:06 AM
Hello James,

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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
James
Top achievements
Rank 1
answered on 30 Dec 2013, 04:08 PM
Hi Atanas, 

  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


0
Atanas Korchev
Telerik team
answered on 30 Dec 2013, 05:37 PM
Hello James,

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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Wandelson
Top achievements
Rank 1
answered on 08 Oct 2015, 07:19 PM

{"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 ? 

 

 

0
Daniel
Telerik team
answered on 12 Oct 2015, 12:19 PM
Hello,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
jackie
Top achievements
Rank 1
Answers by
Daniel
Telerik team
James
Top achievements
Rank 1
Atanas Korchev
Telerik team
Wandelson
Top achievements
Rank 1
Share this question
or