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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 18.01.2008, 04:26   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
axStart: tutorial AIF Webservices with C# AX40SP2
Источник: http://axstart.spaces.live.com/Blog/...C0A0!242.entry
==============


Update & delete web service with AIF and C#
There are a lot of questions about the update and delete in AIF and AX 40 SP2. Well it is not so complex. The Axd wizard will generate those new AIF functions but be aware. Turn on the ‘user update’ property on your AOT query. If you don’t do that, you will run into TTS transaction errors. Also check if there is a primary index on that table because they will provide the key fields for your web service. In case of update or delete, these fields are also used to find that record in AX.
I have created an update query on the CustTable (query name axdCustTable), next I run the Axd Wizzard.
Next I will scan and register these new services. Finally I will deploy these new services in my Web Service. (CustTableService.asmx) (DEGUG: turn on directory browsing in IIS, so you can see it). By the way the functions without ‘list’ will be gone in 5.0 so don’t use them now also.
Results:
AX40 SP1
AX40 SP2
· createCustTable
· createListCustTable
· findEntityKeyListCustTable
· findListCustTable
· readCustTable
· readListCustTable
· createCustTable
· createListCustTable
· findEntityKeyListCustTable
· findListCustTable
· readCustTable
· readListCustTable
· deleteCustTable
· deleteListCustTable

Next we have to do some coding in Visual Studio. Create a console application and register this Web Service in Visual Studio. Use reference name (CustTableWebService).
C# code
Код:
static void Main(string[] args)
        {
            CustTableWebService.CustTableService axCustTableService   = new CustTableWebService.CustTableService();
            axCustTableService.Credentials = System.Net.CredentialCache.DefaultCredentials; // Use the current user to authenticate in IIS
            CustTableWebService.AxdCustTable AxCustTableObject        = new CustTableWebService.AxdCustTable();
            CustTableWebService.AxdEntity_CustTable[] AxCustTableData = new CustTableWebService.AxdEntity_CustTable[1];
            CustTableWebService.DocumentContext AxDocumentContext     = new CustTableWebService.DocumentContext();
            CustTableWebService.EntityKey[] AxEntityKey; 
            CustTableWebService.KeyField[] AxKeyField;
 
            //credentias START
            AxDocumentContext.MessageId             = Guid.NewGuid().ToString();
            AxDocumentContext.SourceEndpoint        = "FAWebService"; 
            AxDocumentContext.DestinationEndpoint   = "LocalEndPoint";
            AxDocumentContext.SourceEndpointUser    = Environment.ExpandEnvironmentVariables("%userdomain%\%username%");
            //credentials END
 
            //create record
            AxCustTableData[0] = new CustTableWebService.AxdEntity_CustTable();
            AxCustTableData[0].AccountNum           = "4999";
            AxCustTableData[0].CustGroup            = "10";
            AxCustTableData[0].Name                 = "C# customer";
            AxCustTableData[0].LanguageId           = "en-us";      //mandatory for AXClass
            AxCustTableData[0].Currency             = "eur";        //mandatory for AXClass
            AxCustTableData[0].CustClassificationId = "01";         //mandatory for AXClass
            AxCustTableObject.CustTable = AxCustTableData; 
            AxEntityKey = axCustTableService.createListCustTable(AxDocumentContext, AxCustTableObject);
 
            System.Console.WriteLine("check if customer 4999 is created and press any key to continue");
            System.Console.ReadKey();
 
            //update record
            AxDocumentContext.MessageId = Guid.NewGuid().ToString();
            AxCustTableObject.CustTable[0].Name     = "C# customer updated";
            AxEntityKey = axCustTableService.createListCustTable(AxDocumentContext, AxCustTableObject);
            System.Console.WriteLine("check if customer 4999 is update and press any key to continue");
            System.Console.ReadKey();
 
            //read record
            AxKeyField = new CustTableWebService.KeyField[1];
            AxKeyField[0] = new CustTableWebService.KeyField();
            AxKeyField[0].Field                    = "AccountNum";
            AxKeyField[0].Value                    = "4000";
            AxEntityKey =  new CustTableWebService.EntityKey[1];
            AxEntityKey[0]= new CustTableWebService.EntityKey();
            AxEntityKey[0].KeyData = AxKeyField;
 
            AxDocumentContext.MessageId = Guid.NewGuid().ToString();
            AxCustTableObject = axCustTableService.readListCustTable(AxDocumentContext, AxEntityKey);
            System.Console.WriteLine("read customer 4000 "+AxCustTableObject.CustTable[0].Name);
            System.Console.ReadKey();
 
            //delete record
            AxKeyField[0].Value = "4999";
            AxDocumentContext.MessageId = Guid.NewGuid().ToString();
            axCustTableService.deleteListCustTable(AxDocumentContext, AxEntityKey);
            System.Console.WriteLine("check if customer 4999 is deleted and press any key to continue");
            System.Console.ReadKey();
        }
When it is not working:
Look in AX Basic / Periodic / AIF/ Exceptions. If you see error lines, there is an error in the AX configuration, when you don’t see errors there is a bug in your IIS configuration
Errors like below tells you that you are missing mandatory fields.
Invalid document schema. The following error was returned: The element 'CustTable' in namespace 'http://schemas.microsoft.com/dynamics/2006/02/documents/CustTable' has invalid child element 'CustClassificationId' in namespace 'http://schemas.microsoft.com/dynamics/2006/02/documents/CustTable'. List of possible elements expected: 'Currency' in namespace 'http://schemas.microsoft.com/dynamics/2006/02/documents/CustTable'.



Источник: http://axstart.spaces.live.com/Blog/...C0A0!242.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
axStart: Enrich AIF with the power of offline working (roadmap) Blog bot DAX Blogs 0 07.05.2008 15:05
axStart: How to use XSLT in AIF and what’s wrong with empty xml Nodes. Blog bot DAX Blogs 0 27.04.2008 18:07
axStart: What to do when AIF is not working and how to code: Blog bot DAX Blogs 0 23.12.2007 17:51

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 01:24.