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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 19.05.2016, 12:44   #8  
Link is offline
Link
Британский учённый
Аватар для Link
Соотечественники
 
568 / 513 (19) +++++++
Регистрация: 25.11.2005
Адрес: UK
Записей в блоге: 9
Вот еще по теме: Preserve data when AIF service call fails

Dynamics AX AIF is great for all kind of interfaces and integration with 3rd party applications. By default AIF has an built-in transaction mechanism that prevents your system to become inconsistent if something goes wrong during processing.

Here is an example of a simple method which writes message data and the current transaction level into a table

X++:
    [SysEntryPointAttribute]
    public void call(Description _message)
    {
        ERPServiceTable serviceTable;

        serviceTable.Message = _message;
        serviceTable.Info = strFmt("%1", appl.ttsLevel());
        serviceTable.insert();
    }
Here is the service call from a C# console application

PHP код:
    var client = new ERPService.ERPServiceClient();
    
client.ClientCredentials.Windows.ClientCredential.Domain "YOUR_DOMAIN";
    
client.ClientCredentials.Windows.ClientCredential.UserName "YOUR_USER";
    
client.ClientCredentials.Windows.ClientCredential.Password "YOUR_PASSWORD";

    var 
context = new ERPService.CallContext();
    
context.MessageId Guid.NewGuid().ToString();
    
client.call(context"Service Call"); 
When you call the service the result looks like this: Notice, the transaction level is already 1 although there is no ttsbegin in code.

AIF service call

But what happens when something goes wrong during processing the service call (e.g. posting a journal fails). Here is as simple method which can be used to simulate such a situation:

X++:
    [SysEntryPointAttribute]
    public void callWithError(Description _message,boolean _error)
    {
        this.call(_message);
        if(_error)
        {
            throw error("Exception!");
        }
    }
When you call the service method with the error flag set to FALSE, the message is written to the table and stays there.

X++:
    context.MessageId = Guid.NewGuid().ToString();
    client.callWithError(context, "Service Call without error", false);
However if you call the method with the error flag set to TRUE a rollback is triggered and your data is gone!

X++:
    try
    {
            context.MessageId = Guid.NewGuid().ToString();
            client.callWithError(context, "Service Call 2 with error", true);
    }
    catch
    {
            Console.WriteLine("The service failed as expected!");
    }
The table contains only 2 entries for both successful service calls. The data from the third service call is gone.

Service call with error not saved

However, if you want to keep the initial data for a post mortem analysis, this behavior is a problem. One way to work around this rollback is to reduce the transaction level back to 0 by calling an additional ttscommit. This will ensure no rollback will delete the transmitted data. Finally, raise the ttslevel back to 1 for further processing.

X++:
    [SysEntryPointAttribute]
    public void callWithError(Description _message,boolean _error = false)
    {
        this.call(_message);

        ttsCommit;
        ttsBegin;
       
        if(_error)
        {
            throw error("Exception!");
        }
    }
When you call the service method with the error flag set to true, the method still fails. But the initial transmitted data is preserved and can be used for analysis or manual processing.

Service call with error preserverd
BTW.

A more relaxed way to address this issue is to separate interfaces from business logic. For example provide two methods, one to transmit the data and another to process the data after it was successfully transmitted. If a second method is not an option (for what reason ever) write a batch class which processes the data. However, if you require immediate processing and a second call is not feasible this workaround may help.
__________________
Людям физического труда для восстановления своих сил нужен 7-8 часовой ночной сон. Людям умственного труда нужно спать часов 9-10. Ну а программистов будить нельзя вообще.
За это сообщение автора поблагодарили: Logger (1).
Теги
aif, ax2012, user connection

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Вызов веб-сервиса Ax 2012 R3 из 1C 8.2 Bega DAX: Программирование 8 06.02.2015 13:30
Вызов Web-сервиса из Ax2009 samolalex DAX: Программирование 6 21.11.2012 14:50
daxdilip: How to: Configure Dynamics AX AIF Services to listen for SSL Requests (https) Blog bot DAX Blogs 0 23.01.2011 10:12
Dianne Siebold: AIF Top Ten Blog bot DAX Blogs 1 22.04.2008 11:19
Вызов веб-сервиса из аксапты dzeaman DAX: Программирование 18 24.12.2005 13:22

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

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

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