Skip to content

[Bug]: Call a locally exposed web service #2164

@porta76

Description

@porta76

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.

  1. Create a test codeunit in a Business Central extension.
  2. Enable HttpClient requests for the extension (Allow HttpClient Requests = true).
  3. In the test codeunit, construct the OData V4 endpoint URL for the published service.
  4. Use HttpClient in AL to send a request to the endpoint without authentication headers.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Unrelated to AL-GoThis issue is unrelated to AL-GobugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions