Skip to main content

Notifications

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 119

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.

  • Suggested answer
    JAngle Profile Picture
    95 on at
    RE: How to consume web service from AL

    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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 874

#2
YUN ZHU Profile Picture

YUN ZHU 829 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 595

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans