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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 26.04.2010, 19:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
emeadaxsupport: Creating an MSMQ message that can be consumed by AX AIF process
Источник: http://blogs.msdn.com/emeadaxsupport...f-process.aspx
==============

Last week I had the need to use the MSMQ adapter in AX2009. Setting up the AX and Windows side of this was pretty straightforward as there is a great article on TechNet detailing how to do this (http://technet.microsoft.com/en-us/l.../aa834340.aspx). This meant I could generate outgoing messages from AX pretty easily. However when I wanted to test incoming messages I needed to write some code to create messages in MSMQ which could be successfully consumed by AX's inbound AIF channel.

The X++ job below will create a message in an MSMQ queue which can be read back in by AX's inbound AIF MSMQ process. There are a few points to note about this:

- The queue created in MSMQ is transactional and authenticated is checked. The account of the user running this X++ job has to be granted permissions on the queue to be allowed to write to it. The account of the AOS has to be granted permissions to be allowed to read from the queue (for the inbound AIF process to run).
- The code below uses Microsoft.Dynamics.IntegrationFramework.Adapter.dll just because I am familiar with it, it is not a requirement to use this, you can generate the XML however you want.
- We use System.Messaging.MessageQueueTransaction because the queue is transactional, without this no message would be generated to the queue and also no error would be raised.
- We use the streamwriter to preserve the format of the XML, setting the message.body() direct will result in incorrectly encoded XML in the message body.
- We set AttachSenderId and UseAuthentication - these are required for the message to be readable by AX.
- This is written in X++, but as it uses managed code to do all the work it can be simply transposed to C# or whichever language you like.

To use this just set up a new public queue on your machine called "MyTest", check transactional and authenticated and grant full control to your AOS account and your own account. Add the attached XML file in C:\Aif\. Then run the job, it will create a message! Now you can configure and inbound AIF channel in AX which looks at your myTest queue, enable it for the salesOrder.create action and AX will be able to read from it MSMQ queue and create a sales order.

static void MSMQ_outbound(Args _args)
{
System.Messaging.MessageQueue messageQueue;
System.Messaging.Message message;
System.Messaging.MessageQueueTransaction transaction;
Microsoft.Dynamics.IntegrationFramework.Adapter.FileSystem fileSystem;
Microsoft.Dynamics.IntegrationFramework.Adapter.TransportMessage transportMessage;
System.IO.StreamWriter streamWriter;
;
fileSystem = new Microsoft.Dynamics.IntegrationFramework.Adapter.FileSystem();
transportMessage = fileSystem.ReadFile('C:\\AIF\\SalesOrderCreate.xml');

try
{
transaction = new System.Messaging.MessageQueueTransaction();
transaction.Begin();
messageQueue = new System.Messaging.MessageQueue(@'.\MyTest');
message = new System.Messaging.Message();

streamWriter = new System.IO.StreamWriter(message.get_BodyStream());
streamWriter.Write(transportMessage.get_MessageXml());
streamWriter.Flush();
message.set_AttachSenderId(true);
message.set_UseAuthentication(true);
messageQueue.Send(message, transaction);
transaction.Commit();

}
catch
{
info("An error occurred");
}

messageQueue.Dispose();
message.Dispose();
streamWriter.Dispose();
transportMessage = null;
fileSystem = null;

info("Message sent");

}




Источник: http://blogs.msdn.com/emeadaxsupport...f-process.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
За это сообщение автора поблагодарили: Ivanhoe (0).
Теги
aif, msmq

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
emeadaxsupport: What changes are required if we change the Business Connector Proxy used by AX 2009 Generated AIF Web services Blog bot DAX Blogs 0 29.03.2010 15:05
emeadaxsupport: You get a warning message when deploying the AX 2009 smmOpportunityReports report library Blog bot DAX Blogs 0 19.02.2010 05:07
emeadaxsupport: List of fixes that improve performance of certain features in Dynamics AX 2009 Blog bot DAX Blogs 0 13.10.2009 19:06
emeadaxsupport: You get the following warning message in BizTalk Server 2006 R2/2009 - The message does not contain a body part Blog bot DAX Blogs 0 18.09.2009 03:13
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 21:51.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.