Saturday, November 17, 2018

A1 Repo: Simple Pagination for WCF Service Operation

It is never a good idea to paginate on the client.  This post is about a simple pagination for a WCF service operation.  For this work I need a RequestModel and a ResponseModel.



The RequestModel contains two properties; PageNumber and PageSize.  The RequestModerl could contain sort order by certain fields but because this is simple pagination no sorting by fields is supported in this note.

The ResonseModel has a list of items of reference type T and other properties which could be used by the client.

The service in question has tree operations:



We are particularly interested in the implementation of  ResponseModel GetEmployeesByRequest(RequestModel request) and here it is:



The interesting part is the OrderBy > Skip > Take.  Note that in case that the client asks for a page which does not exist the actual page is reset to the last page so we know the records to skip. Note that what is sent to the client has been mapped to a specific DataContract and it was done using a mapping extension very similar to how it was done in A1 Repo: Explicit Mapping Using Extensions Methods Rather than Using AutoMapper.

This little POC is tested using a console application.  Note that when a service reference is created the  client proxy offers the possibility of using asynchronous programming.



For this note the Adventure2012 database was used.  The ORM employed was Entity Framework and the model was created using the Entity Data Model Wizard > Code First from Database.

To Table of contents


No comments:

Post a Comment

A1 Repo: Simple Pagination for WCF Service Operation

It is never a good idea to paginate on the client.  This post is about a simple pagination for a WCF service operation.  For this work I nee...