![]() |
#1 |
Участник
|
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(); } 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, напишите личное сообщение администратору. |
|