dattaprasaddhuri Ответов: 0

Push-уведомление не собирается на iOS-устройство после хостинга?


Я хочу отправить Push-уведомление для отправки устройства ios с помощью сервиса WCF.
Когда я запускаю службу с локального компьютера, push-уведомление отправляется на сервер
но когда он размещен на iis, уведомление не отправляется.

я получаю следующую ошибку:

ошибка:-
A call to SSPI failed, see inner exception


внутреннее исключение:
System.ComponentModel.Win32Exception " +
    "(0x80004005): The message received was unexpected or badly formatted


Что я уже пробовал:

public string PushNotificationIOS(string deviceID)
        {
            string devicetocken=string.Empty;//  iphone device token

            try
            {

                //devicetocken = "";//  iphone device token
                devicetocken = deviceID;//  iphone device token
                int port = 2195;
                String hostname = "gateway.sandbox.push.apple.com";
                //String hostname = "gateway.push.apple.com";

                string certificatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Certificate/Certificates.pem");
                //Server.MapPath("final.p12");

                string certificatePassword = "Sudesi@123";// "mohs123$";

                X509Certificate2 clientCertificate = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.MachineKeySet);
                X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);

                TcpClient client = new TcpClient(hostname, port);
                SslStream sslStream = new SslStream(
                                client.GetStream(),
                                false,
                                new RemoteCertificateValidationCallback(ValidateServerCertificate),
                                null
                );


                sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, false);



                //// Encode a test message into a byte array.
                MemoryStream memoryStream = new MemoryStream();
                BinaryWriter writer = new BinaryWriter(memoryStream);

                writer.Write((byte)0);  //The command
                writer.Write((byte)0);  //The first byte of the deviceId length (big-endian first byte)
                writer.Write((byte)32); //The deviceId length (big-endian second byte)

                byte[] b0 = HexString2Bytes(devicetocken);
               // WriteMultiLineByteArray(b0);

                writer.Write(b0);
                String payload;
                string strmsgbody = "";
                int totunreadmsg = 20;
                strmsgbody = "Your call for complaint no. M00011 has been registered in our system. - Your ticket no for your communication is 100000000065";

                //Debug.WriteLine("during testing via device!");
                //Request.SaveAs(Server.MapPath("APNSduringdevice.txt"), true);

                payload = "{\"aps\":{\"alert\":\"" + strmsgbody + "\",\"badge\":" + totunreadmsg.ToString() + ",\"sound\":\"mailsent.wav\"},\"acme1\":\"bar\",\"acme2\":42}";

                writer.Write((byte)0); //First byte of payload length; (big-endian first byte)
                writer.Write((byte)payload.Length);     //payload length (big-endian second byte)

                byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
                writer.Write(b1);
                writer.Flush();

                byte[] array = memoryStream.ToArray();
                //Debug.WriteLine("This is being sent...\n\n");
                //Debug.WriteLine(array);

                sslStream.Write(array);
                sslStream.Flush();


                //Debug.WriteLine("Write failed buddy!!");
                //Request.SaveAs(Server.MapPath("Writefailed.txt"), true);


                client.Close();
                //Debug.WriteLine("Client closed.");
                //Request.SaveAs(Server.MapPath("APNSSuccess.txt"), true);

                return "True";
            }
            catch (AuthenticationException ex)
            {
                //Console.WriteLine("Authentication failed");
                //client.Close();
                //Request.SaveAs(Server.MapPath("Authenticationfailed.txt"), true);
                return ex.Message;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

0 Ответов