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 :
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
    133 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

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,577

#2
YUN ZHU Profile Picture

YUN ZHU 888 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 778 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans