AIF 中的服务一般会提供八种操作, 分别为create,delete,find,findKeys,getKeys,read,update, getChangeKey
我们今天来讨论如何使用AIF Service 中的create方法去读取 Dynamics AX中的数据
- 注册 SalesSalesOrderService 服务
- 创建一个NetTcp类型的端口,命名为TestAIFOperation,添加SalesSalesOrderService 服务的create方法
- 在VS2010种创建一个console类型的项目
- 取得端口中的服务地址(WSDL URI): http://RD7145D0511:8101/DynamicsAx/Services/TestAIFOperation
- 添加引用,右击Reference/Add Service Reference,将WSDL URI复制进去,点击Go按钮,再点击确定
- 执行一下代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using TestAIFCreateMethod.ServiceReference1;
namespace TestAIFCreateMethod { class Program { static void Main(string[] args) { SalesOrderServiceClient client = new SalesOrderServiceClient(); CallContext context = new CallContext(); context.Company = "CEU";
AxdSalesOrder salesOrder = new AxdSalesOrder(); AxdEntity_SalesTable[] salesTable = new AxdEntity_SalesTable[1]; salesTable[0] = new AxdEntity_SalesTable(); salesTable[0].CustAccount = "1101"; salesTable[0].PurchOrderFormNum = @"$amp;"; salesTable[0].ReceiptDateRequested = DateTime.Today;
AxdEntity_SalesLine[] lines = new AxdEntity_SalesLine[2]; lines[0] = new AxdEntity_SalesLine(); lines[0].ItemId = "1000"; lines[0].SalesQty = 100; lines[0].SalesUnit = "ea";
lines[1] = new AxdEntity_SalesLine(); lines[1].ItemId = "1003"; lines[1].SalesQty = 15; lines[1].SalesUnit = "ea";
salesTable[0].SalesLine = lines; salesOrder.SalesTable = salesTable;
try { EntityKey[] entityKey=client.create(context, salesOrder); foreach (EntityKey key in entityKey) { Console.WriteLine(); Console.WriteLine("Output result:"); KeyField[] fields = key.KeyData; foreach(KeyField field in fields) { Console.WriteLine("Field: {0}",field.Field); Console.WriteLine("Value: {0}",field.Value); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { client.Close(); } Console.ReadKey(); } } } |
- 运行,结果如下:
在AX中可以找到如下的记录: