firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
367 stars 131 forks source link

Issue To reach FireBase #252

Closed skogkatt closed 3 years ago

skogkatt commented 3 years ago

Hi everyone,

I'm implementing the Admin sdk firebase for my ASP.net project (that provides only API for the front apps to call)

i'm calling the Send method to send notification to a specific token.

When i'm doing this from a consoleapplication (existing in project or a new one) its working perfectly.

When i'm exposing the API and calling it from Postman or so, i had this error message : "StatusCode": 50000, "TechnicalMessage": "System.Net.Sockets.SocketException (0x80004005): Une tentative de connexion a échoué car le parti connecté n’a pas répondu convenablement au-delà d’une certaine durée ou une connexion établie a échoué car l’hôte de connexion n’a pas répondu à System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)\r\n à System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)\r\n à System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)", "UserFriendlyMessage": null

means that it cannot reach the server correctly maybe.

this is my code :

    [HttpPost]
    public async Task SendNotificationFCM()
    {

        string topic = "Channel";
        string tokenjos = "tokenjos";
        string tokenhk = ""tokenhk";
        string response = string.Empty;
        FirebaseAdmin.Messaging.TopicManagementResponse reponse = null;
        FirebaseAdmin.Messaging.FirebaseMessaging messaging = null;
        FirebaseApp defaultapp = null;

        var registrationTokens = new List<string>()
        {
            tokenjos ,tokenhk
        };

        var AppBee = FirebaseApp.GetInstance("[DEFAULT]");

        if (AppBee == null)
        {

            defaultapp = FirebaseApp.Create(new AppOptions()
            {
                Credential = GoogleCredential.GetApplicationDefault(),
            });

            messaging = FirebaseAdmin.Messaging.FirebaseMessaging.GetMessaging(defaultapp);
        }

        var message = new FirebaseAdmin.Messaging.Message()
        {
            Notification = new FirebaseAdmin.Messaging.Notification()
            {
                Title = "titre test",
                Body = "body pour test aussi",
            },

            Topic = topic,
        };

        var result = await messaging.SendMulticastAsync(message).ConfigureAwait(false);

        Request.CreateResponse(HttpStatusCode.OK, response);
    }

Thank's in advance.

hiranya911 commented 3 years ago

The above code has at least one syntax error. SendMulicastAsync() accepts a MulticastMessage instance. You've passed a Message. The above code shouldn't even compile. Also the stacktrace doesn't indicate any Firebase SDK API calls, so I doubt it has anything to do with the FCM API.

I suggest you resolve the compilation issues in the code first. If you continue encounter issues, carefully debug your code and try to isolate the API call that's causing the error. You can also add a try-catch around SDK API calls and log the original exceptions to get more details. Once you have additional information, please report a new issue with a repro or at least some debug information.