博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[AX]AX2012 AIF(七):创建.NET程序集变换器
阅读量:7110 次
发布时间:2019-06-28

本文共 3196 字,大约阅读时间需要 10 分钟。

在增强型AIF端口中可以配置出入站变换器,它的作用是在消息处理过程中()对消息做前后置处理,比如来源消息不是很规范,我们需要在正式处理前做数据的整理,这个就可以使用变换器来完成。顺便要说明的是,管道也是用来处理消息的,它与变换器是有区别的:管道可用于同步/异步数据交换,而变换器只能应用于异步交换;调用时机上入站消息在放入到消息队列前应用变换器,从入站消息队列取出消息正式处理前应用管道。

有两种类型的变换器可用,一是使用XSLT对XML格式的消息做处理变换,第二种则是我们使用.NET开发的程序集变换器,它可以处理任何自定义的格式,比如逗号分隔的CSV格式。一个.NET变换器实际上是在.NET的Class library工程中创建一个实现Microsoft.Dynamics.IntegrationFramework.Transform.ITransform接口的类,在目录C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin下可以找到需要引用的程序集Microsoft.Dynamics.IntegrationFramework.dll。

一个.net变换器类是这个样子的:

using System.Text;using System.IO;using System.Xml;using Microsoft.Dynamics.IntegrationFramework.Transform;namespace AssemblyTransformTest{    public class Class1 : ITransform    {        public void Transform(System.IO.Stream input, System.IO.Stream output, string config)        {            StreamReader sreader = new StreamReader(input);            XmlTextWriter xwriter = new XmlTextWriter(output, Encoding.UTF8);            string[] fieldArray;            string[] dataArray;            string rootName = "Customers";            string rowName = "Customer";            int i;                        // Get the element names from the headings            string lineIn = sreader.ReadLine();            fieldArray = lineIn.Split(',');            // Start writing the XML file.            xwriter.Formatting = Formatting.Indented;            xwriter.WriteStartDocument();            xwriter.WriteComment("customers.xml file");            xwriter.WriteStartElement(rootName);            lineIn = sreader.ReadLine();            while (lineIn != null)            {                // Loop through each line of data in the file.                xwriter.WriteStartElement(rowName);                 dataArray = lineIn.Split(',');                // Write each element.                for (i = 0; i <= dataArray.GetUpperBound(0); i++)                {                    xwriter.WriteElementString(fieldArray[i], dataArray[i]);                }                // Write the  end element.                xwriter.WriteEndElement();                lineIn = sreader.ReadLine();            }            sreader.Close();            // Write the  end element.            xwriter.WriteEndElement();            xwriter.Close();        }    }}

它处理CSV输入格式的数据:

Num,AccountName,CustGroup,Currency1,Fourth Coffee,20,USD2,Graphic Design Institute,20,USD3,Lucerne Publishing,20,EUR

返回XML格式的的结果:

1
Fourth Coffee
20
USD
2
Graphic Design Institute
20
USD
3
Lucerne Publishing
20
EUR

在AIF端口中使用这个.NET变换器前,我们还需要先将它导入到AX,导入工具在Tools > Application Integration Framework > Manage transforms窗口,在这里创建一个.net程序集类型的变换器,装载相应的程序集文件dll,选择要应用的变换器类,一个程序集是可以包含多个变换器类的。需要注意变换器程序集需要同时拷贝分发到服务器bin目录(C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\Bin)和客户端bin目录(C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin)。

 

 

转载地址:http://udmhl.baihongyu.com/

你可能感兴趣的文章
Mvc Moq HttpContext
查看>>
linux ,mac连接, git pull error, chmod修改文件的权限/chown修改文件和目录的所有者
查看>>
Java类载入器 ClassLoader的解析
查看>>
js判段URL是否可用(js判段网络是否不可用)
查看>>
六一儿童节PHP宝宝又被围剿了,迅速围观!
查看>>
HTML---简介
查看>>
.Net JIT
查看>>
Yahoo Programming Contest 2019 D-Ears
查看>>
java 的exception throw try catch
查看>>
jQuery原型方法each使用和源码分析
查看>>
9.4、文件包含
查看>>
Harbinger vs Sciencepal
查看>>
.NET深入解析LINQ框架1
查看>>
FlipView 知识准备
查看>>
3D绘图计算器(geogebra[5.0.385.0])使用QQ浏览器打开下载
查看>>
深入浅出交换类排序算法(转)
查看>>
junit spring
查看>>
装饰模式(Decorator) ...
查看>>
[Android] ImageView.ScaleType设置图解
查看>>
解决IE8不兼容 background-size
查看>>