AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 05.06.2013, 17:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
equalized: Dynamics Ax custom WCF service with paging support
Источник: http://www.kevinroos.be/2013/06/dyna...aging-support/
==============

Hi all,

Lately I’ve been busy developing WCF services to communicate with .NET web applications. All of these web services are custom-made and are using .NET data contracts so that every application uses the same contracts. Due to the high amount of data and performance we had to implement some kind of paging. I had no clue that Ax even has paging support but it does and it does this with properties on the QueryRun objects.

For example purposes I’ve made a service which uses .NET request and response contracts. I prefer this way over X++ data contracts because this is more reusable and flexible on the client side. The code is self-explanatory to me but you can always pose questions of course.

The request contract:

123456789[DataContract]public class ItemListRequest{ [DataMember] public long StartingPosition { get; set; } [DataMember] public long NumberOfRecordsToFetch { get; set; }}
The response contract:

1234567891011121314151617181920[DataContract][KnownType(typeof(Item))]public class ItemListResponse{ [DataMember] public int TotalNumberOfRecords { get; set; } [DataMember] public ArrayList Items { get; set; }} [DataContract]public class Item{ [DataMember] public string Id { get; set; } [DataMember] public string Name { get; set; }}
The service implementation:

12345678910111213141516171819202122232425262728293031323334353637[SysEntryPointAttribute]public Blog.WCFPaging.DataContracts.ItemListResponse getItems(Blog.WCFPaging.DataContracts.ItemListRequest _request){ Blog.WCFPaging.DataContracts.Item item; System.Collections.ArrayList itemList = new System.Collections.ArrayList(); Blog.WCFPaging.DataContracts.ItemListResponse response = new Blog.WCFPaging.DataContracts.ItemListResponse(); QueryRun queryRun = new QueryRun(queryStr(InventTable)); InventTable inventTable; ; if( CLRInterop::getAnyTypeForObject(_request.get_StartingPosition()) > 0 && CLRInterop::getAnyTypeForObject(_request.get_NumberOfRecordsToFetch()) > 0) { response.set_TotalNumberOfRecords(QueryRun::getQueryRowCount(queryRun.query(), maxInt())); queryRun.enablePositionPaging(true); queryRun.addPageRange(_request.get_StartingPosition(), _request.get_NumberOfRecordsToFetch()); // At least one order by field should be declared when using paging SysQuery::findOrCreateDataSource(queryRun.query(), tableNum(InventTable)).addOrderByField(fieldNum(InventTable, ItemId)); } while(queryRun.next()) { inventTable = queryRun.get(tableNum(InventTable)); item = new Blog.WCFPaging.DataContracts.Item(); item.set_Id(inventTable.ItemId); item.set_Name(inventTable.NameAlias); itemList.Add(item); } response.set_Items(itemList); return response;}
Calling the service from a .NET application:

1234567891011121314151617181920212223242526int pageSize = 10; using (var client = new BLOGPagingServiceClient()){ BLOGPagingServiceGetItemsResponse response = null; var request = new ItemListRequest() { StartingPosition = 1, NumberOfRecordsToFetch = pageSize }; do { response = client.getItems(new BLOGPagingServiceGetItemsRequest() { CallContext = new CallContext(), _request = request }); foreach (Item item in response.response.Items) { Console.WriteLine(String.Format("{0, -10} - {1}", item.Id, item.Name)); } Console.WriteLine("-----"); request.StartingPosition += pageSize; } while (response.response.Items.Count > 0);}
Paging on a QueryRun is implement since Ax 2009, more info on paging: http://msdn.microsoft.com/nl-be/libr...(v=ax.50).aspx

I wonder why this isn’t implemented in the AIF services or is it? If anyone knows please leave a comment about it.



Источник: http://www.kevinroos.be/2013/06/dyna...aging-support/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
sumitsaxfactor: Create Your First Custom Service [AX 2012] Blog bot DAX Blogs 0 19.05.2012 19:14
Dave Froslie: Visual Studio 10 Coded UI / Action Recordings support for Microsoft Dynamics AX 2012 Blog bot DAX Blogs 0 07.10.2011 21:11
daxdilip: Whats New in Dynamics AX 2012 (A brief extract from the recently held Tech Conf.) Blog bot DAX Blogs 7 31.01.2011 12:35
Dynamics AX: WCF: The Enterprise Service Bus for Dynamics AX and the rest of the Microsoft Stack Blog bot DAX Blogs 0 10.03.2009 16:05
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 10:13.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.