web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

How to consume web service from AL

(0) ShareShare
ReportReport
Posted on by 131

hello community first of all good day I have a somewhat unusual situation

I am developing in business central a small project to consume a web service to which I have to connect to obtain some data for its manipulation

below I show my code of how I currently make the call of this web service from AL:

Variables
        uri: Text;
        RequestHeaders: HttpHeaders;
        RequestMessage: HttpRequestMessage;
        RequestContent: HttpContent;
        HttpClient: HttpClient;
        ResponseMessage: HttpResponseMessage;
        Content: HttpContent;
        text2Send: Text;
        PushHttpAddress: Text[80];
        lSuccess: Boolean;
        ResponseInText: Text;
        
        ////////// Code///////////
        
        content.Clear();
        HttpClient.Clear();
        RequestHeaders.Clear();
        RequestMessage.Content().Clear();
        ResponseMessage.Content().Clear();
        ResponseMessage.Headers().Clear();

        lSuccess := False;
        PushHttpAddress := 'https:/XXXXXXXXXXXXXXXXXXXXX';

        uri := pushHttpAddress;

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


        text2Send := PBAXML; ------> Here i send the XML Soap buil before
        RequestContent.writefrom(Text2Send);
        RequestContent.GetHeaders(RequestHeaders);

        RequestHeaders.Remove('Content-Type');
        RequestHeaders.Add('Content-Type', 'text/xml; charset=utf-8');
        RequestHeaders.Add('SOAPAction', 'http://www.uniXXXXXXXXXXXXXXXXXXX');

        RequestMessage.Content(RequestContent);

        if not HttpClient.Send(RequestMessage, ResponseMessage) then begin
            Message('Bad');
            Error('');
        end;

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

Well now the question here is that the aforementioned code works correctly in a local environment of central business but when I place the code in a Sanbox in the cloud it does not return a successful response

I don't understand why it doesn't work in the cloud


I hope you can guide me with your knowledge

and thanks for your time.

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    159 on at

    This project relates to a video where a US postal service web service is consumed. It works in the cloud as I have it deployed: https://github.com/hougaard/Youtube-Video-Sources/tree/master/USPS%20App 

    There are 3 videos that go with the project this is the first: https://youtu.be/kVvRnMNjeiM 

    this is a smaller video which is might be more applicable if your expected response is json: https://youtu.be/D5jzrgl1EP0 

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,496 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 961 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 870 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans