3

I have been using PushSharp for Apple notifications for some time in both a web service and a windows service without any issues.

On adding the code for Google GCM, it works perfectly fine on my web service and a console app I converted the service to, but it fails miserably in the windows service even when run on the same server (Amazon EC2 Instance)

The following code gives an "Authentication Failed" error for the GCM notification and has no error for the Apple notification. However, If I run the same code in my web service or a console app on the same server, it works fine.

Dim push As PushBroker = New PushBroker

Try
        AddHandler push.OnNotificationSent, AddressOf NotificationSent
        AddHandler push.OnNotificationFailed, AddressOf NotificationFailed

        Dim appleCert = File.ReadAllBytes("FILENAME")
        push.RegisterAppleService(New ApplePushChannelSettings(False, appleCert, "PASSWORD"))
        push.RegisterGcmService(New GcmPushChannelSettings("API_KEY"))
        push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("ANDROID-TOKEN").WithJson("{""alert"":""Hello World!"",""badge"":1,""sound"":""sound.caf""}"))
        push.QueueNotification(New AppleNotification().ForDeviceToken("IOS-TOKEN").WithContentAvailable(1))

    Catch ex As Exception

    End Try

If I remove the line:

   push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("ANDROID-TOKEN").WithJson("{""alert"":""Hello World!"",""badge"":1,""sound"":""sound.caf""}"))

it works perfectly on both the windows service and the web service.

Can anyone see what I am doing wrong? It is not a firewall issue. I turned off the firewall and it still didn't work. I had a lot of other code and have distilled it down to the above code to make sure there were no hidden issues.

EDIT. I set up a console app copying the code from the windows service and used the Browser API Key instead of the Server API key.

This works perfectly on both my local machine and the server machine. However the windows service still gets the same error whichever API key I use.

UPDATE: Although the Windows Service is receiving the error, it does actually send two notifications and then no more. If I stop the service and start it again, I get another two notifications even though the notification error is still being returned.

I'm really stuck. I can just continuously run the console app for now, but its hardly perfect. Any help would be gratefully received.

halfer
  • 19,824
  • 17
  • 99
  • 186
grayson
  • 945
  • 1
  • 11
  • 28
  • I'm getting the same similar issue. The Apple push notification working fine as a service, but not the GCM side. Any solution yet? – Nick N Nov 22 '14 at 19:15
  • Do you think it's a timing issue where the service isn't registered yet before calling: QueueNotification. I'm thinking of adding wait statements to try and determine this. – Nick N Nov 22 '14 at 19:17
  • An excellent thought, but I am not convinced though because I am not adding anything to my push queue (db storing notifications) until around 5 minutes after the service starts. The code above is a simplification. Mu code doesn't actually call QueueNotification until as I say up to five minutes and not less than 30 seconds. – grayson Nov 23 '14 at 20:31
  • ...after registering service. And also, the above code runs perfectly in a console app. I hope I'm wrong though and you find a solution. – grayson Nov 23 '14 at 20:38
  • I'll give the timing changes a try. Here's a related issue on github. https://github.com/Redth/PushSharp/issues/445 – Nick N Nov 24 '14 at 01:53
  • We actually got it working on our prod box by creating a new server key (inside google developer console) while on the production box. The new key worked fine inside the application that's launched from Task Manager on our prod box and working fine on our dev box as well manually through Visual Studio. – Nick N Nov 24 '14 at 20:42

1 Answers1

0

I had a similar issue - everything worked fine in Visual Studio but on the production server AndroidGcm authentication failed.

I figured it was something to do with the IP list in the 'Key for server applications' so I tried regenerating one with the IP address of my server. This didn't work.

Eventually in response to one of the above comments and another thread elsewhere I logged onto the Google Play Developer Console from the server and created a new key, without specifying any IP addresses.

Using this key then fixed my problem

ED-209
  • 4,706
  • 2
  • 21
  • 26