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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 20.02.2015, 19:14   #1  
Blog bot is offline
Blog bot
Участник
 
25,491 / 846 (79) +++++++
Регистрация: 28.10.2006
dynamics-coe: Outbound HTTP adapter for AIF in Dynamics AX 2012
Источник: http://blogs.msdn.com/b/dynamics-coe...r-for-aif.aspx
==============

There are lots of inbound integration adapters in AX2012 R3, including the File System, TCP, HTTP, Azure Service Bus and MSMQ, but just 2 outbound ones: File System and MSMQ. Both of them are asynchronous only and slow due to disc operations, very bad indeed in our brave cloud world.

Let me close this gap and introduce a small HTTP adapter written in X++, which uses the .NET HttpWebRequest API.

The core method is just 66 lines long:

public void sendMessage(AifGatewayMessage gatewayMessage)
{
System.Net.HttpWebRequest httpWebRequest;
System.Net.HttpWebResponse httpWebResponse;

System.IO.Stream requestStream,
messageStream,
responseStream;
System.IO.StreamReader responseStreamReader;

System.Byte[] byteArray;
System.Text.Encoding encoding;
int msgLength;

str response;

if (! adapterIntialized)
throw error("@SYS95134");

httpWebRequest = System.Net.WebRequest::Create(transportAddress) as System.Net.HttpWebRequest;

try
{
if (gatewayMessage.parmMessageStream() != null)
{
messageStream = gatewayMessage.parmMessageStream();
messageStream.Read(byteArray, 0, int642int(messageStream.get_Length()));
}
else
{
encoding = System.Text.Encoding::GetEncoding(gatewayMessage.parmEncoding());
byteArray = encoding.GetBytes(gatewayMessage.parmMessageXml());
}
msgLength = byteArray.get_Length();

// Set HttpWebRequest properties
httpWebRequest.set_Method("POST");
httpWebRequest.set_ContentLength(msgLength);
httpWebRequest.set_ContentType(strFmt("text/xml; charset=%1", gatewayMessage.parmEncoding()));

requestStream = httpWebRequest.GetRequestStream();

// Writes a sequence of bytes to the current stream
requestStream.Write(byteArray, 0, msgLength);
// Close stream
requestStream.Close();

// Sends the HttpWebRequest, and waits for a response.
httpWebResponse = httpWebRequest.GetResponse();

if (httpWebResponse.get_StatusCode() == System.Net.HttpStatusCode::OK)
{
// Get response stream into StreamReader
responseStream = httpWebResponse.GetResponseStream();
responseStreamReader = new System.IO.StreamReader(responseStream);
response = responseStreamReader.ReadToEnd();
}
httpWebResponse.Close();
}
catch (Exception::CLRError)
{
messageId = gatewayMessage.parmMessageId(); // to re-send if needed

throw error(strfmt("The HTTP adapter is unable to transmit the message to %1. Error: %2", transportAddress, AifUtil::getClrErrorMessage()));
}
} Attached you may find an XPO file with the source code, as well as a tiny runtime listener in C# and a simple test routine to play with.




Источник: http://blogs.msdn.com/b/dynamics-coe...r-for-aif.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
aif, ax2012

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
DAX: How to gain additional value from the Microsoft application platform with Microsoft Dynamics AX 2012 R2 Blog bot DAX Blogs 3 21.06.2013 15:16
Sample Design Patterns: Book Give-away: 'Microsoft Dynamics AX 2012 Development Cookbook' Blog bot DAX Blogs 1 12.05.2012 16:55
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11
dynamics-ax: Interview with Microsoft's Lachlan Cash on his new role, AX 2012 and more Blog bot DAX Blogs 6 22.04.2011 14:55
axinthefield: Dynamics AX Event IDs Blog bot DAX Blogs 0 01.03.2011 22:11

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

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

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