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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

send Json data to external WebService from AX2009

(0) ShareShare
ReportReport
Posted on by

How can I realize to send JSON data to an external Webservice from AX2009?

I think I have to create an external C# tool where I put my data (URL, Login Data and Data to post) in and than send the stuff from there. Am I right?

How can I easily realize this and how can I handle this inside AX?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Brandon Wiese Profile Picture
    17,790 on at

    Sending a request and obtaining a response from X++ is pretty straightforward with the System.Net.HttpWebRequest.  I have some sample code from AX 4 that unfortunately I do not have handy at the moment, but it's not appreciably different from how you would do it in VB.net.  Lots of examples out there.

    You could further make working with JSON a little easier with a .net library, like Newtonsoft's JSON.net, adding it to References in the AOT.

    No, you do not have to write anything in C# outside of AX.  You can definitely call an external web services directly from X++ in AX 4, 2009, and 2012.

  • Mea_ Profile Picture
    60,286 on at

    Hi ChrisR75,

    You can build c shrap library or use existing one and then use it in AX. It's quite simple, all you need is to add reference under references node in AOT. This topic is covered on msdn msdn.microsoft.com/.../cc598160(v=ax.50).aspx

  • Community Member Profile Picture
    on at

    Hi, basically I tried it inside AX with System.Net.HttpWebRequest but it does not work. It crashes with a marshall error (unsupported type) and many more thing.

  • Brandon Wiese Profile Picture
    17,790 on at

    Is this the problem you're having?

    blogs.msdn.microsoft.com/.../how-to-cast-between-webrequest-and-httpwebrequest

  • Community Member Profile Picture
    on at

    I am absolutely not sure because I played around that lot and I lost the overview

  • Brandon Wiese Profile Picture
    17,790 on at

    There are plenty of good examples online for using HttpWebRequest in 2009.  In your case, JSON rendered to string becomes the body of the POST instead of the typical XML, but that shouldn't cause you any grief if you're good with JSON.

  • Community Member Profile Picture
    on at
    actually I thought I have a proper example found and used to implement


    System.Net.HttpWebRequest request; System.Net.HttpWebResponse response; System.Byte[] byteArray; System.IO.Stream dataStream; System.IO.StreamReader streamReader; //System.Net.ServicePoint servicePoint; //System.Net.ServicePointManager servicePointManager; System.Net.NetworkCredential credentials; System.Net.WebHeaderCollection headers; CLRObject clrObj; System.Text.Encoding utf8; str headerString; str returnValue; SENParameters parameters = SENParameters::find(); headerString = strfmt("Basic %1:%2", parameters.RTMUser, parameters.RTMPassword); headers = new System.Net.WebHeaderCollection(); headers.Add("Authorization", headerString); credentials = new System.Net.NetworkCredential(parameters.RTMUser, parameters.RTMPassword); // HttpWebResponse resp = req.GetResponse() as HttpWebResponse; System.Net.ServicePointManager::set_Expect100Continue(false); clrObj = System.Net.WebRequest::Create(parameters.RTMServiceUrl); request = clrObj; request.set_Method('POST'); request.set_Timeout(90000); request.set_Headers(headers); request.set_Credentials(credentials); utf8 = System.Text.Encoding::get_UTF8(); byteArray = utf8.GetBytes(jsonData); request.set_ContentType(@"application/x-www-form-urlencoded"); request.set_ContentLength(byteArray.get_Length()); dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.get_Length()); dataStream.Close(); try { response = request.GetResponse(); } catch (Exception::CLRError) { jsonData = ""; } dataStream = response.GetResponseStream(); streamReader = new System.IO.StreamReader(dataStream); returnValue = streamReader.ReadToEnd();
  • Brandon Wiese Profile Picture
    17,790 on at

    That looks like an AX 2012 example.  I'm pretty sure you can't use an array type in AX 2009, i.e. System.Byte[].  You definitely couldn't in AX 4.  That would generate an unsupported type error.

  • Brandon Wiese Profile Picture
    17,790 on at

    Maybe you could.  2009 was a long time ago all things considered.  I see examples of people doing it after all.

    Which line gives you the unsupported type error?

  • Community Member Profile Picture
    on at

    dataStream = request.GetRequestStream();

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 28

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans