How to call a NAV2016 SOAP (codeunit) Webservice from nav

Hope someone could help me in my quest to be able to consume a NAV SOAP (Codeunit) webservice from another nav instance (both running on NAV2016 RTC so c\al code only).

In NAVinstance1 I have a NAV WebService (Codeunit) that returns me the next available number in a number series. I would like to call this WebService (CU) form NAVinstance2 to be able to assign the next available number in that system (without going into too much detail it is for LSRetail POS terminal requesting HO number sequence)

I have seen posts but nothing seems to work for me..
- https://community.dynamics.com/blogs/post/?postid=471c157c-2cbc-4d40-bd3d-da3d2e71cc14
- https://vjeko.com/2012/09/30/web-services-black-belt-consuming-nav-web-services-using-pure-cal/

Answers

  • BEsterhuizenBEsterhuizen Member Posts: 13
    edited 2025-02-12
    Ok have managed to get this working....please see below using https://navfreak.com/2017/02/25/dynamics-nav-how-to-consume-an-external-soap-web-service-with-netdotnet-interop/

    sb := sb.StringBuilder();
    sb.Append('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:get="urn:microsoft-dynamics-schemas/codeunit/GET_HO_NumberSeries">');
    sb.Append('<soapenv:Header>');
    //sb.Append('<test:userPassword>xxxxxxxx</test:userPassword>');
    //sb.Append('<test:userId>xxxx</test:userId>');
    sb.Append('</soapenv:Header>');
    sb.Append('<soapenv:Body>');
    sb.Append('<get:HOReturnNextNumber>');
    sb.Append('<get:noSeriesCode>T-GIFTCARD</get:noSeriesCode>');
    sb.Append('<get:errorMsg></get:errorMsg>');
    sb.Append('<get:nextNumberSeriesNumber></get:nextNumberSeriesNumber>');
    sb.Append('</get:HOReturnNextNumber>');
    sb.Append('</soapenv:Body>');
    sb.Append('</soapenv:Envelope>');

    //XMLRequest
    // complete sericve URL
    uriObj := uriObj.Uri('http://nav-test.xxxxxxxx.local:8047/xxxxxxUAT/WS/xxxx LIVE/Codeunit/GET_HO_NumberSeries');
    lgRequest := lgRequest.CreateDefault(uriObj);
    lgRequest.Method := 'POST';
    lgRequest.ContentType := 'text/xml';
    // only use the page name form the URL
    lgRequest.Headers.Add('SOAPAction','GET_HO_NumberSerie');

    // XMLResponse
    lgRequest.Credentials := credentials.DefaultCredentials;
    lgRequest.Timeout := 120000;
    stream := stream.StreamWriter(lgRequest.GetRequestStream(),ascii.ASCII()); // falling over on this line
    stream.Write(sb.ToString());
    stream.Close();
    lgReponse := lgRequest.GetResponse();

    str := lgReponse.GetResponseStream();
    reader := reader.XmlTextReader(str);
    document := document.XmlDocument();
    document.Load(reader);
    reader.Close();
    str.Close();
    Filename := 'c:\temp\Result_' + FORMAT(TODAY,0,9) + '_' + FORMAT(CREATEGUID) + '.xml';
    document.Save(Filename);


    Note that you are using the mscorlib so you need to write it manually in the Subtype and then tab to expose the methods.....(caught me until someone pointed it out to me) System you need to just select the System v4 and then you will see the system exposed methods too.
    Name DataType Subtype
    **Type mscorlib to find core libary*** Integer
    sb DotNet System.Text.StringBuilder.'mscorlib'
    stream DotNet System.IO.StreamWriter.'mscorlib'
    str DotNet System.IO.Stream.'mscorlib'
    ascii DotNet System.Text.Encoding.'mscorlib'
    **.Net system only and then look for rest*** Integer
    uriObj DotNet System.Uri.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    lgRequest DotNet System.Net.HttpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    lgReponse DotNet System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    reader DotNet System.Xml.XmlTextReader.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    document DotNet System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    credentials DotNet System.Net.CredentialCache.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    Filename Text
    6j2lzajw3q0a.png



Sign In or Register to comment.