title: PushSharp GCM "Authentication Failed"
body: <p>I have been using PushSharp for Apple notifications for some time in both a web service and a windows service without any issues.</p>
  
  <p>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)</p>
  
  <p>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. </p>
  
  <pre><code>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
  </code></pre>
  
  <p>If I remove the line:</p>
  
  <pre><code>   push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("ANDROID-TOKEN").WithJson("{""alert"":""Hello World!"",""badge"":1,""sound"":""sound.caf""}"))
  </code></pre>
  
  <p>it works perfectly on both the windows service and the web service.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>I'm really stuck. I can just continuously run the console app for now, but its hardly perfect. Any help would be gratefully received.</p>