Windows Server 2008上的Apple推送通知无法正常工作

时间:2014-06-30 10:40:06

标签: asp.net apple-push-notifications windows-server-2008 windows-server pushsharp

我被困住了,我希望有人会帮助我。

有几天我试图从Windows Server 2008发送苹果推送通知。但是没有发送或接收任何内容。事实上,我已经将所有内容都移动到了简单的mvc应用程序,因此它可以更容易调试,我注意到当我尝试强制发送推送通知时它会挂起(在push.StopAllServices(true);) 他们使用相同的方法发送通知,从Windows服务器2012R2工作(现在仍然是),所以我猜证书和代码都没问题。

  • 我正在使用Windows服务& push sharp发送通知。目标框架:4
  • 测试项目是MVC 2.0目标框架4
  • 我在服务器上安装了asp.net 4.5
  • 我已通过mmc中的mmc安装证书(私钥可用,授予IUSR和IIS_USRS权限)和受信任的根证书颁发机构。
  • 端口2195已打开

以下是代码:

private void Initizalize()
        {
            push = new PushBroker();

            //appleCert is path to my .p12 certificate on disk.     
            var cert = new ApplePushChannelSettings(false, appleCert, "***");

            //I've read somewhere that it was helpful to force send notifications. Well, in my case it's not. 
            var settings = new PushServiceSettings();

            settings.AutoScaleChannels = false;
            settings.Channels = 3;
            settings.MaxAutoScaleChannels = 3;


            //Wire up the events for all the services that the broker registers
            push.OnNotificationSent += NotificationSent;
            push.OnChannelException += ChannelException;
            push.OnServiceException += ServiceException;
            push.OnNotificationFailed += NotificationFailed;
            push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
            push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
            push.OnChannelCreated += ChannelCreated;
            push.OnChannelDestroyed += ChannelDestroyed;

            push.RegisterAppleService(cert, settings);
        }

public void SendPush()
        {
            Initizalize();
            var token = hard coded token that exists;
            var output = "msg";
            push.QueueNotification(new AppleNotification()
                                       .ForDeviceToken(token)
                                       .WithAlert(output)
                                       .WithBadge(1)
                                       .WithSound("default"));

            push.StopAllServices(true);
        }

它引发了事件“OnNotificationSent”,没有别的。

还有一件事可能很重要。发送和接收推送通知已经并且正在从Windows Server 2012开始工作,但它是windows azure虚拟机,因此安装证书是不同的。

有什么想法吗? 即使是无法完成的信息也会有所帮助!

编辑: 一个问题解决了:

显然你需要引用NewtonSoft.Json才能调用StopAllServices。它现在没有挂起,但设备没有收到任何信息。

1 个答案:

答案 0 :(得分:1)

在Windows Server 2008上看起来,apns证书私钥必须已授予想要使用它的用户的权限。

正如我之前写的那样,我已经为IIS_USRS授予了它,但这只适用于在IIS下运行的应用程序。由于我使用的是Windows服务,因此无法正常工作。 所以我做的是检查用户的Windows服务(服务 - >登录为)并授予该用户的证书私钥的权限。