-
Notifications
You must be signed in to change notification settings - Fork 188
[Bug]: Call a locally exposed web service #2164
Description
AL-Go version
8.3
Describe the issue
We are creating automated test cases for our integration solution and need to call a published OData V4 endpoint from AL. The web service is published through webservices.xml, and the endpoint is accessible externally.
Scenario
From AL code we attempt to call the published OData V4 URL using HttpClient.
Expected behavior
Since no authentication header is provided, we expect the endpoint to return HTTP 401 (Unauthorized).
Actual behavior
When the request targets the same Business Central instance (local call), the request fails before reaching the endpoint.
However, if we change the URL to an external web service, the HttpClient request works as expected.
Additional information
- HTTP requests are enabled for the extension (Allow HttpClient Requests = true)
- The OData endpoint works as expected when called from a local docker.
We would like to understand whether calling an OData endpoint from AL in the same BC instance is supported and why the request fails instead of returning 401 Unauthorized.
Expected behavior
Web service to call locally
WebServiceManagement.LoadRecords(WebServiceAggregate);
WebServiceAggregate.SetRange("Object Type", WebServiceAggregate."Object Type"::Page);
WebServiceAggregate.SetRange("Object ID", Page::"External WS Trigger API");
WebServiceAggregate.SetRange(Published, true);
WebServiceAggregate.FindFirst();
PageUri := WebServiceManagement.GetWebServiceUrl(WebServiceAggregate, ClientType::ODataV4);
Steps to reproduce
Publish an OData V4 web service using webservices.xml.
- Create a test codeunit in a Business Central extension.
- Enable HttpClient requests for the extension (Allow HttpClient Requests = true).
- In the test codeunit, construct the OData V4 endpoint URL for the published service.
- Use HttpClient in AL to send a request to the endpoint without authentication headers.
- Execute the test.
Additional context (logs, screenshots, etc.)
If the same HttpClient code is used to call an external web service, the request works as expected.