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 :
Small and medium business | Business Central, N...
Suggested Answer

Recreate code in NAV 2018

(0) ShareShare
ReportReport
Posted on by 131

Hello Community, first of all thank you very much for taking the time to read my question


I have a small problem with a development in Nav 2018, I have to consume a web service, I know how to do it by programming in Visual Studio Code with the AL extension


But right now I am developing with C / AL and I see that HttpClient variables are used as .NET variables

In AL I do it in the following way and the consumption of the web service works correctly for me

codeunit 50600 "Test Web Service"
{
    procedure TestWebService(PBARFCEmisor: Text; PBARFCReceptor: Text; PBATotal: Text; PBAUUID: Text)              //procedure TestWebServiceDoBrasil(var PBAXMLinTEXT: Text)
    var
        XMLDomMgt: Codeunit "XML DOM Mgt.";
        PBAXML: Text;
        PBADOCUMETXML: XmlDocument;

        uri: Text;
        RequestHeaders: HttpHeaders;
        RequestMessage: HttpRequestMessage;
        RequestContent: HttpContent;
        HttpClient: HttpClient;
        ResponseMessage: HttpResponseMessage;
        Content: HttpContent;
        text2Send: Text;
        PushHttpAddress: Text[80];
        lSuccess: Boolean;
        ResponseInText: Text;


        Pos: Integer;
        Length: Integer;
        PBAEstado: Text;
    begin

        ///////////////////// Construccion XML exitosa //////////
        PBAXML := '?re='   PBARFCEmisor   '&rr='   PBARFCReceptor   '&tt='   PBATotal   '&id='   PBAUUID   '';
        XMLDomMgt.LoadXMLDocumentFromText(PBAXML, PBADOCUMETXML);
        PBADOCUMETXML.WriteTo(PBAXML);
        //PBAXMLinTEXT := PBAXML;
        //Message(PBAXML);




        ///Construccion de la Llamada Web Service///

        content.Clear();
        HttpClient.Clear();
        RequestHeaders.Clear();
        RequestMessage.Content().Clear();
        ResponseMessage.Content().Clear();
        ResponseMessage.Headers().Clear();

        lSuccess := False;
        PushHttpAddress := 'https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc?wsdl';

        uri := pushHttpAddress;

        RequestMessage.SetRequestUri(uri);
        RequestMessage.Method := 'POST';


        text2Send := PBAXML;
        RequestContent.writefrom(Text2Send);
        RequestContent.GetHeaders(RequestHeaders);

        RequestHeaders.Remove('Content-Type');
        RequestHeaders.Add('Content-Type', 'text/xml; charset=utf-8');
        RequestHeaders.Add('SOAPAction', 'http://tempuri.org/IConsultaCFDIService/Consulta');

        RequestMessage.Content(RequestContent);

        if not HttpClient.Send(RequestMessage, ResponseMessage) then begin
            Error('Error en el Web Service');
        end;

        Content := ResponseMessage.Content();
        Content.ReadAs(ResponseInText);
        lSuccess := ResponseMessage.IsSuccessStatusCode();
        //Message(ResponseInText);

        Pos := StrPos(ResponseInText, '')   10;
        Length := StrPos(ResponseInText, '');
        Length := Length - Pos;
        PBAEstado := CopyStr(ResponseInText, Pos, Length);

        Message('CFDI: '   PBAEstado);


    end;

}

My question is how can I do the above code in C / AL using .NET variables


Thanks again for your time.

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,269 Super User 2026 Season 1 on at

    There are several examples in standard NAV, check codeunit 7820 or 2020 there is a invoke rest api function which uses HttpClient.

  • Yael Suarez Profile Picture
    131 on at

    Before anything, thank you for taking the time to read my question.

    Seeing the code units you mentioned, I managed to code the following:

    PBAXML := TxtXML;   //// It is the XML that I copy and paste from SoapUI to verify the response of the web service, save it in a constant text variable
    
    HttpClient:=HttpClient.HttpClient();
    HttpClient.DefaultRequestHeaders.Add('SOAPAction', 'http://tempuri.org/IConsultaCFDIService/Consulta');
    HttpClient.BaseAddress := uri.Uri('https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc?wsdl');
    
    ResponseMessage := HttpClient.PostAsync(PBAXML,content).Result;
    
    Result := ResponseMessage.Content.ReadAsStringAsync.Result;
    MESSAGE(Result);

    But I still can't get the answer that I get with the code that I made in visual studio code with the extension AL


    Do you have any other point of view that you could share with me your knowledge to consume the web service?


    Thanks again for your time and I send you my regards

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,965 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,125 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 961 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans