Skip to content

Sending notification from WCF in .NET Framework 4.8 is stuck  #366

@Thordax

Description

@Thordax

I have a WCF (Windows Communication Foundation) server. Recently, I tried to update the sending of notifications from a basic https request to Firebase Admin SDK.

The code I'm using in console version works perfectly from my machine. On the other hand, the same code used from the WCF on the same machine remains blocked when sending.

Here's the method I use:

public static async Task<string> SendMessage(string deviceId, string message, string IdSem, string UrlResponseSEM,
    string Auth_Message = "", string auth_key = "", bool isAuthMessageDansNotif = true)
{
    string color = "#0072C6";
    bool hasErrors = false;
    List<string> logList = new List<string> { "[=FCM_SendMessage=]" };

    try
    {
        logList.Add($"[deviceId:{deviceId}] [message:{message}] [IdSem:{IdSem}] [Auth_Message:{Auth_Message}] [color:{color}]");
        logList.Add($"[isAuthMessageDansNotif:{isAuthMessageDansNotif}]");

        Message messagingMessage = null;
        if (isAuthMessageDansNotif)
        {
            messagingMessage = new Message
            {
                Token = deviceId,
                Data = new Dictionary<string, string>
                {
                    { "time", DateTime.Now.ToString() },
                    { "idsem", IdSem },
                    { "urlresponse", UrlResponseSEM },
                    { "message", message },
                    { "auth_message", Auth_Message },
                    { "auth_key", auth_key }
                }
            };
        }
        else
        {
            messagingMessage = new Message
            {
                Token = deviceId,
                Data = new Dictionary<string, string>
                {
                    { "time", DateTime.Now.ToString() },
                    { "idsem", IdSem },
                    { "urlresponse", UrlResponseSEM },
                    { "message", message }
                }
            };
        }

        string postData = JsonConvert.SerializeObject(messagingMessage);
        logList.Add($"[postData={postData}]");

        LogSeo.MyLog.Debug("FCM_SENDING_MESSAGE ...");

        var response = await FirebaseMessaging.DefaultInstance.SendAsync(messagingMessage).ConfigureAwait(false);
        LogSeo.MyLog.Debug("FCM_SENDING_MESSAGE OK");

        return response;
    }
    catch (Exception ex)
    {
        hasErrors = true;
        logList.Add($"ERROR > {ex.GetAllExceptions()} {ex.StackTrace}");
        return $"ERROR:{ex.Message}";
    }
    finally
    {
        logList.Add("[=FCM_SendMessage=]");
        string strLog = string.Join(Environment.NewLine, logList);
        if (hasErrors)
        {
            LogSeo.MyLog.Error(strLog);
        }
        else
        {
            LogSeo.MyLog.Debug(strLog);
        }
    }
}

The method remains blocked at the following line:

var response = await FirebaseMessaging.DefaultInstance.SendAsync(messagingMessage).ConfigureAwait(false);

Could you please tell me what could have caused the problem?

Note that I'm using a proxy and that there may also be a firewall on the machine. Are there any specific ports that need to be unblocked?

If so, how can this work from my executable?

Thanks in advance for your help, and have a nice day,

I tried to send a notification through FCM from my WCF.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions