microsoft / microsoft/AL-Go

[Bug]: Call a locally exposed web service

Open
#2,164 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug stale Unrelated to AL-Go
Dominant language
PowerShell
Stars
506
Forks
203
Avg merge
4d 22h
Merged PRs (30d)
6

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.

  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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the AL test codeunit scenario and the webservices.xml-published OData V4 endpoint, then reproduce the local HttpClient request with and without authentication and compare it with the external-service case. Done means establishing whether same-instance calls are supported, identifying why the local request fails before returning 401, and recording the supported behavior or required change.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.