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 :
Microsoft Dynamics NAV (Archived)

Consume External WebService from NAV Codeunit

(1) ShareShare
ReportReport
Posted on by

Hello,

TASK: Call external soap web service in Codeunit ( send the request and get the response )
(web service can be any available web service, the aim is just to send data and get the response.)

Does someone have a real example how to use this call?
I have been searching for different examples but nothing really work. 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Have you checked this series of blog post

    https://www.kauffmann.nl/2015/11/26/web-services-examples-part-1-the-basic-pattern/

    In your try to call the external web service what error are you encountering and what is current code to execute the call.

  • Suggested answer
    Daniel Rimmelzwaan Profile Picture
    3,485 on at

    Here's a 90 minute session with a bunch of examples: https://youtu.be/FLFc_U3oQlA 

  • Suggested answer
    keoma Profile Picture
    32,729 on at
  • Community Member Profile Picture
    on at

    Hello,

    Thank you all for reading my post.

    I made something like this code now but I got BAD REQUEST error.

    Is there a problem because of service.svc extension?

    -------------------XMLHttp and XmlDocumentare Automation -----------------

    IF ISCLEAR(XMLHttp) THEN

     CREATE(XMLHttp,TRUE, TRUE);

    IF ISCLEAR(XMLDocument) THEN

     CREATE(XMLDocument, TRUE, TRUE);

    XMLHttp.open('POST', 'localhost/Service1.svc&;, FALSE);

    XMLHttp.setRequestHeader('Host', 'http://localhost:8083/');

    XMLHttp.setRequestHeader('Content-Type','text/xml');

    XMLHttp.setRequestHeader('SOAPAction','CreateFixedAsset');

    XMLHttp.send('<?xml version="1.0" encoding="UTF-8"?>' +

    ' <soap:Envelope xmlns:soapenv="schemas.xmlsoap.org/.../&quot; xmlns:tem="http://tempuri.org/&quot;>' +

      ' <soap:Header/>'+

       '<soap:Body>'+

          ' <tem:CreateFixedAsset>'+

             '  <tem:No>5654</tem:No>'+

             '  <tem:Description>?</tem:Description>'+

              ' <tem:SerialNo>?</tem:SerialNo>'+

            '   <tem:VendorNo>10000</tem:VendorNo>'+

              ' <tem:ResponsibleEmployee>AH</tem:ResponsibleEmployee>'+

             '  <tem:MaintenanceVendorNo>10000</tem:MaintenanceVendorNo>'+

              ' <tem:Class>FINANCIAL</tem:Class>'+

              ' <tem:Subclass>CAR</tem:Subclass>'+

              ' <tem:Location>ADM</tem:Location>'+

              ' <tem:BudgetedAsset>0</tem:BudgetedAsset>'+

        '   </tem:CreateFixedAsset>'+

    '    </soap:Body>'+

    '</soap:Envelope>');

    MESSAGE(XMLHttp.statusText);   ---- returns bad request

    //save as xmldoc

    IF XMLHttp.readyState = 4 THEN BEGIN

     XMLDocument := (XMLHttp.responseXML);

     XMLDocument.save('C:\Users\milet\Desktop\xxx.xml');

    END;

  • Verified answer
    Community Member Profile Picture
    on at

    Dear all,

    This code acctually works fine. Problem was in .svc extersion.

    With other service link like /host/page   it works fine.

    IF ISCLEAR(XMLHttp) THEN

    CREATE(XMLHttp,TRUE, TRUE);

    IF ISCLEAR(XMLDocument) THEN

    CREATE(XMLDocument, TRUE, TRUE);

    XMLHttp.open('POST', 'url', FALSE);

    XMLHttp.setRequestHeader('Host', 'hostName');

    XMLHttp.setRequestHeader('Content-Type','text/xml');

    XMLHttp.setRequestHeader('SOAPAction','soapactionName');

    XMLHttp.send('<?xml version="1.0" encoding="UTF-8"?>' +

    ' <soap:Envelope xmlns:soapenv="schemas.xmlsoap.org/.../" xmlns:tem="http://tempuri.org/&quot;>' +

     ' <soap:Header/>'+

      '<soap:Body>'+

         ' <tem:CreateFixedAsset>'+

            '  <tem:No>5654</tem:No>'+

             ' <tem:Location>ADM</tem:Location>'+

             ' <tem:BudgetedAsset>0</tem:BudgetedAsset>'+

       '   </tem:CreateFixedAsset>'+

    '    </soap:Body>'+

    '</soap:Envelope>');

    MESSAGE(XMLHttp.statusText);

    //save as xmldoc

    IF XMLHttp.readyState = 4 THEN BEGIN

    XMLDocument := (XMLHttp.responseXML);

    XMLDocument.save('\path\xxx.xml');

    END;

  • Ahmad Bani Naser Profile Picture
    10 on at

    Hi Snjezana Miletic,

    Cloud you please share fob object.

    Thanks in advance

  • Rishi Chourey Profile Picture
    143 on at

    Hello Everyone I am also trying to exectue in same way but  I am getting error 500, Internal Server Error does anyone faced this kind of error.

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 > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans