17
Views
3
Comments
C# Extension for Sending FCM Messages Causing Timeout – Need Sample Code
Question

Hi Community,

I have created a C# extension in OutSystems to send Firebase Cloud Messaging (FCM) push notifications using the HTTP v1 API. The code compiles fine, but when I execute it inside OutSystems, the request times out.

Here is the method I am currently using:

/// Sends a message and returns FCM message name (projects/{pid}/messages/{id}).


public async Task SendAsync(FcmMessage message, CancellationToken ct = default)

{

    if (message is null) throw new ArgumentNullException(nameof(message));


    var url = $"https://fcm.googleapis.com/v1/projects/{_projectId}/messages:send";


    using var req = new HttpRequestMessage(HttpMethod.Post, url)

    {

        Content = new StringContent(

            JsonSerializer.Serialize(new { message }, JsonOptions),

            Encoding.UTF8,

            "application/json")

    };


    req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await GetAccessTokenAsync(ct));


    // Basic retry for 429/5xx

    const int maxAttempts = 4;

    int attempt = 0;

    TimeSpan delay = TimeSpan.FromMilliseconds(400);

    while (true)

    {

        attempt++;

        using var toSend = req.Clone();

        using var resp = await _http.SendAsync(toSend, ct);

        string body = await resp.Content.ReadAsStringAsync(ct);


        if (resp.IsSuccessStatusCode)

        {

            using var doc = JsonDocument.Parse(body);

            return doc.RootElement.TryGetProperty("name", out var n)

                ? (n.GetString() ?? string.Empty)

                : string.Empty;

        }


        if (attempt < maxAttempts && IsTransient(resp.StatusCode))

        {

            await Task.Delay(delay, ct);

            delay = TimeSpan.FromMilliseconds(Math.Min(delay.TotalMilliseconds * 2, 4000));

            continue;

        }


        throw new FcmException((int)resp.StatusCode, body);

    }

}

This works fine when tested outside of OutSystems (in a console app), but within OutSystems it results in timeouts.

👉 Could anyone please share a working sample of a C# extension in OutSystems that sends an FCM push notification (preferably using the v1 API with OAuth2 Bearer token)?

👉 Or point out if I need to adjust how I handle HttpClient / HttpRequestMessage in the OutSystems environment?

Any guidance or code samples would be greatly appreciated.

Thanks in advance,

Kanisious Museka

2019-01-07 16-04-16
Siya
 
MVP

Since it works in your console app, the code is fine. Most likely the OutSystems server can’t reach fcm.googleapis.com. Quick test: in your module go to Logic → REST → Consume → Add Single Method, set URL to https://fcm.googleapis.com, then click Test. If that times out, it’s a network/proxy/firewall issue on the server.

2025-12-29 06-17-15
Deepak Raj M

SqlConnection cn = new SqlConnection

            {

                ConnectionString = ssConnectionString

            };

            SqlCommand cmd = new SqlCommand

            {

                Connection = cn,

                CommandText = "",

                CommandType = CommandType.StoredProcedure

            };

            cmd.CommandTimeout = 0;
Please try likr this in C# code

2025-08-07 06-30-56
Amit J
Champion

Hi @KANISIOUS MUSEKA


Most likely causes: deadlock from async/await in the extension, TLS/proxy/firewall differences in the server environment, or reusing a single HttpRequestMessage across attempts. 

Fixes that reliably work inside OutSystems Integration Studio extensions are (in order of importance):
use ConfigureAwait(false) on all awaits inside async methods, create a new HttpRequestMessage per attempt (don’t reuse one instance), ensure TLS 1.2 is enabled, and expose a synchronous wrapper the platform calls (or return the Task result synchronously with GetAwaiter().GetResult()).

Also verify outbound connectivity (proxy/firewall) from the server and add robust try/catch logging to surface the real error. 
You can look into this code CSharp.cs 

CSharp.cs
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.