使用PushSharp在WCF中进行CryptographicException

时间:2014-05-09 22:20:37

标签: wcf push-notification apple-push-notifications pushsharp cryptographicexception

我有一个WCF服务,使用APNS向IOS设备发送推送通知。我使用以下代码使用PushSharp。

我在“RegisterAppleService”步骤中遇到错误。错误说明是: “CryptographicException未被用户代码处理 参数不正确。“

    private static PushBroker push;

    public string SendNotification()
    {
        push = new PushBroker();
        push.OnNotificationSent += NotificationSent;
        push.OnChannelException += ChannelException;
        push.OnServiceException += ServiceException;
        push.OnNotificationFailed += NotificationFailed;
        push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
        push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
        push.OnChannelCreated += ChannelCreated;
        push.OnChannelDestroyed += ChannelDestroyed;

        var appleCert = File.ReadAllBytes("CERT_FILE_NAME.p12");
        push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "PASSWORD"));

        string devToken = "DEVICE_TOKEN";
        push.QueueNotification(new AppleNotification()
                                   .ForDeviceToken(devToken)
                                   .WithAlert("Hello World!")
                                   .WithBadge(7)
                                   .WithSound("sound.caf"));

我找不到问题的原因。我该如何处理该异常? 谢谢。

1 个答案:

答案 0 :(得分:3)

我怀疑您只使用通过签名请求生成的密钥而不是证书本身。

https://github.com/Redth/PushSharp/wiki/How-to-Configure-&-Send-Apple-Push-Notifications-using-PushSharp

此处提供了步骤,在步骤18中确保您导出的是与密钥关联的证书,而不仅仅是密钥本身。

还要确保您在开发阶段使用development / sandbox ssl证书。