Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

read api response

(1) ShareShare
ReportReport
Posted on by 1,549
Hi,

when i call an api, the response of this call might sometimes result in a different namespaces, but the field names are still the same.

How to read the "errorDescription" field regardless if the namespace is SOAP-1 and ns4 OR if it's SOAP-2 and ns5?? how to do it in x++?

So i have now xmlDocument.loadXml(xml);
what to do next?




Categories:
  • Martin Dráb Profile Picture
    233,743 Most Valuable Professional on at
    read api response
    When the service response with a fault contract, the client library will thrown an exception. You can use the catch statement to get the exception object and then you can work with its properties such as Message.
  • .. Profile Picture
    1,549 on at
    read api response
    Hi Martin,
     
    I read the article, but i don't quite understand what i should do now to get the value inside the "error description" field regardless of how the response look like?
     
    To give you a background of what i'm doing
     
    I'm calling an api, where i'm filling the body of the request by creating an xml filled from d365 data.
    Now this api call will produce a response, and i would like to take a value from that response and store in a field.
     
    The link you gave me is for the response part right? 
    But can you give more explanation of what i should do exactly? More clear steps would be helpful 
  • Suggested answer
    Martin Dráb Profile Picture
    233,743 Most Valuable Professional on at
    read api response
    You normally shouldn't be working with raw SOAP messages at all. You should generate client classes and work with these classes, therefore the implementation details are dealt with for you. It seems that you've artificual created the problem by developing something that you shouldn't be developing, because it's already done and in better than what you've done by yourself.
     
    To see the correct steps, check the documentation page Consume external web services, for instance. Of course, some knowledge of SOAP and WCF may be still needed, if you want to use non-default configuration. 
  • .. Profile Picture
    1,549 on at
    read api response
    Hi,

    just to add to my question, the code I did here was to handle one response, but is there a way to handle both responses? is there a better way to write the code?
     
    
    
    
    What i noticed is that errorXNode is filled correctly regardless if the response contains "SOAP-1 and ns4" or if it's "SOAP-2 and ns5".
    Even though the path specified in the selectSingleNode is SOAP-1 and ns4, how did that work?
    
    it only fails in getXMLElementValue where it's expecting ns5, but the code says ns4
    
    

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Martin Dráb Profile Picture

Martin Dráb 512 Most Valuable Professional

#2
Saalim Ansari Profile Picture

Saalim Ansari 315

#3
Adis Profile Picture

Adis 312 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans