Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Create XMLDocument in AX

(0) ShareShare
ReportReport
Posted on by 110

We have an AX customization that requests and returns freight quotes to our carriers using XML documents.  I need to modify this system for a new carrier that uses the SOAP protocol and web services.  I have successfully programmed AX to send the web request and parse the response using a sample XML file.  Now I am trying to create the XML document within AX2009, and am having trouble getting the SOAP envelope formatted correctly.  I will admit here, that I am not familiar with SOAP at all.  To me, it looks like a specifically formatted XML document that the XML Document class should be able to create.  If it isn't, please steer me in the right direction.

The soap request needs to be formatted as shown below.  Notice that there are two namespaces defined on the soapenv:Envelope node.  That is the portion that I can't figure out how to generate. 

 <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="schemas.xmlsoap.org/.../envelope xmlns:myr="http://myurl.com/" >
  <soapenv:Header/>
  <soapenv:Body>
    <myr:takeSomeAction>
        <node1>?</node1>
    </myr:takeSomeAction>
  </soapenv:Body>
</soapenv:Envelope>

This is the code I have tried..

xmlDoc = XmlDocument::newBlank("UTF-8");
        envelopeNameSpace = 'schemas.xmlsoap.org/.../envelope';
        rateNameSpace = 'http://myRate.ws.odfl.com/';
        soapEnvelope = xmlDoc.appendChild(xmlDoc.createElement3('soapenv','Envelope',envelopeNamespace));
        soapHeader = soapEnvelope.appendChild(xmlDoc.createElement3('soapenv','Header',   envelopeNamespace));
        soapBody = soapEnvelope.appendChild(xmlDoc.createelement3('soapenv','Body', envelopeNamespace));
        MyRateRequest = soapBody.appendChild(xmlDoc.createElement3('myr','GetLTLRateEstimate', rateNameSpace));

*This post is locked for comments

  • lispyj Profile Picture
    110 on at
    RE: Create XMLDocument in AX

    There may be no reason at all, except that we haven't, up to now needed to.  For this task, I used the XMLDocument class to create the SOAP request so that I could make as few changes as possible to the existing code.  The other carriers don't use web services, so the majority of the customization still functions as originally designed by our reseller.

  • Suggested answer
    Joris dG Profile Picture
    17,775 on at
    RE: Create XMLDocument in AX

    That's a lot of code. Any particular reason you couldn't use the "service reference" feature in the AOT?

  • Verified answer
    lispyj Profile Picture
    110 on at
    RE: Create XMLDocument in AX

    Solved!  The server error was not caused by the soap envelope.  Even though my document is formatted differently, the request works correctly.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,304 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,160 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans