AIF Operation -- findKey()

本文介绍了如何通过AIF Service的findKeys操作来获取Dynamics AX中的数据。首先,注册SalesSalesOrderService服务,创建NetTcp端口TestAIFOperation并添加findKeys方法。接着,在Visual Studio中创建一个Console应用,获取服务地址并添加服务引用。最后,执行代码以演示findKeys方法的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AIF 中的服务一般会提供八种操作, 分别为create,delete,find,findKeys,getKeys,read,update, getChangeKey

我们今天来讨论如何使用AIF Service 中的findKeys方法去读取 Dynamics AX中的数据

  1. 注册 SalesSalesOrderService 服务
  2. 创建一个NetTcp类型的端口,命名为TestAIFOperation,添加SalesSalesOrderService 服务的findKeys方法
  3. 在VS2010种创建一个console类型的项目
  4. 取得端口中的服务地址(WSDL URI): http://RD7145D0511:8101/DynamicsAx/Services/TestAIFOperation
  1. 添加引用,右击Reference/Add Service Reference,将WSDL URI复制进去,点击Go按钮,再点击确定
  2. 执行一下代码:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using TestAIFFindKeyMethod.ServiceReference1;

 

namespace TestAIFFindKeyMethod

{

    class Program

    {

        static void Main(string[] args)

        {

            string salesIdValue1 = "SO-101244";

            string salesIdValue2 = "SO-101250";

            SalesOrderServiceClient client = new SalesOrderServiceClient();

            CallContext context = new CallContext();

            context.Company = "CEU";

 

            try

            {

                EntityKey[] entityKey = client.findKeys(context, createQueryCriteria(salesIdValue1,salesIdValue2));

                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();

        }

 

        private static QueryCriteria createQueryCriteria(string salesIdValue1, string salesIdValue2)

        {

            CriteriaElement[] criteriaElements = new CriteriaElement[1];

            criteriaElements[0] = new CriteriaElement();

            criteriaElements[0].DataSourceName = "SalesTable";

            criteriaElements[0].Operator = Operator.Range;

            criteriaElements[0].FieldName = "SalesId";

            criteriaElements[0].Value1 = salesIdValue1;

            criteriaElements[0].Value2 = salesIdValue2;

 

            QueryCriteria queryCriteria = new QueryCriteria();

            queryCriteria.CriteriaElement = criteriaElements;

            return queryCriteria;

        }

 

    }

}

  1. 运行,结果如下:

 

Output result:

Field: SalesId

Value: SO-101244

 

Output result:

Field: SalesId

Value: SO-101245

 

Output result:

Field: SalesId

Value: SO-101246

 

Output result:

Field: SalesId

Value: SO-101247

 

Output result:

Field: SalesId

Value: SO-101248

 

Output result:

Field: SalesId

Value: SO-101249

 

Output result:

Field: SalesId

Value: SO-101250

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值