web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to consume REST API in AX 2009 ?

(0) ShareShare
ReportReport
Posted on by 434

I am getting error when trying to consume REST API from Dynamics AX 2009.

 "The underlying connection was closed: An unexpected error occurred on a send. Received an unexpected EOF or 0 bytes from the transport stream. in ax 2009"

static void IntegrationTest(Args _args)
{
System.Net net;
System.Security.Authentication Auth;
str url;
str method;
str header;
System.Net.HttpWebRequest httpRequest;
System.Net.HttpWebResponse httpResponse;
System.Net.WebHeaderCollection headers;
CLRObject clro;
System.Net.SecurityProtocolType spt;
System.Net.ServicePoint servicePt;

int batchSize = 1024;
System.IO.Stream receiveStream;
System.IO.StreamReader readStream;
System.Text.Encoding encode;
System.Char[] read;
System.Text.StringBuilder sb;
System.String readString;
str contentEncoding;

int countRead;


// url = strfmt("">XXXXXXXXXX/.../session");
method = "POST";

try
{
clro = System.Net.WebRequest::Create("">XXXXXXXXXXXXX/.../session");
httpRequest = clro;
headers = new System.Net.WebHeaderCollection();
headers.Add("username", "XXXXX");
headers.Add("password", "XXXXX");

httpRequest.set_Headers(headers);
httpRequest.set_Method(method);
httpRequest.set_ContentType("application/json");

//Third try start to fix underlying connection
servicePt = httpRequest.get_ServicePoint();
servicePt.set_Expect100Continue(false);

//Third try Ends to fix underlying connection

//First try start to fix underlying connection


// System.Net.ServicePointManager::set_Expect100Continue(false);
// System.Net.ServicePointManager::set_SecurityProtocol(System.Net.SecurityProtocolType::TLS12);

//First Try End to fix underlying connection

//Second try start to fix underlying connection


//spt = System.Net.SecurityProtocolType::Tls;
//System.Net.ServicePointManager::set_SecurityProtocol(spt);

//Second try End to fix underlying connection


info("Start");
httpResponse = httpRequest.GetResponse();           

   // Above line gives error "The underlying connection was closed: An unexpected error occurred on a send. Received an unexpected EOF or 0 bytes from the transport stream. in ax 2009"


info("Ënd")


if (httpResponse)
{
receiveStream = httpResponse.GetResponseStream();
contentEncoding = httpResponse.get_ContentEncoding();

if (contentEncoding)
{
encode = System.Text.Encoding::GetEncoding(contentEncoding);
}
else
{
encode = new System.Text.UTF8Encoding();
}

readStream = new System.IO.StreamReader(receiveStream, encode);
read = new System.Char[batchSize]();

countRead = readStream.Read(read, 0, batchSize);

sb = new System.Text.StringBuilder();
while (countRead > 0)
{
readString = new System.String(read, 0, countRead);
sb.Append(readString);
countRead = readStream.Read(read, 0, batchSize);
}

readStream.Close();

info(sb.ToString());
}
}
catch(Exception::CLRError)
{
throw error(AifUtil::getClrErrorMessage());
}
}

in postman it works with below

Method : Post

URL:- XXXXXXXXX/.../session

body -> Raw-Json

{
 "username""XXXXX",
 "password""XXXX"
}
In my environment we have TLS only not TLS 1.2 
I have the same question (0)
  • SC-19081230-0 Profile Picture
    7 on at
    I have - suddenly - the same problems. 
    Was there any solution for this? 
     
    Søren PC

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 490 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans