从ASP.NET C向iOS发送通知时出错 [英] Getting error while sending notification to iOS from ASP.NET C#

查看:72
本文介绍了从ASP.NET C向iOS发送通知时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

收到错误验证失败,因为远程方已关闭传输流。



我尝试过:



getting error as "Authentication failed because the remote party has closed the transport stream."

What I have tried:

int port = 2195;
           string hostname = "gateway.sandbox.push.apple.com";
         //  String hostname = "gateway.push.apple.com";
           String certificatePath = Server.MapPath("PushnotificationDev.p12");
           X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "password");
           X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);

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

           try
           {
              // client.Connect(hostname,port);
               //sslStream.AuthenticateAsServer(hostname, certificatesCollection, SslProtocols.Default, true);
               ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
               sslStream.AuthenticateAsServer(clientCertificate, false, SslProtocols.Ssl3, true);
               MemoryStream memoryStream = new MemoryStream();
               BinaryWriter writer = new BinaryWriter(memoryStream);
               writer.Write((byte)0);
               writer.Write((byte)0);
               writer.Write((byte)32);

               writer.Write(ConvertToByteArray("9865ac6c888e9b9e819b15772e6bcb11d64c659d331a28cf7674050a20fa895p"));
               String payload = "{\"aps\":{\"alert\":\"" + "Hi,, This Is a Sample Push Notification For IPhone.." + "\",\"badge\":1,\"sound\":\"default\"}}";
               writer.Write((byte)0);
               writer.Write((byte)payload.Length);
               byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
               writer.Write(b1);
               writer.Flush();
               byte[] array = memoryStream.ToArray();
               sslStream.Write(array);
               sslStream.Flush();
               client.Close();
           }
           catch (System.Security.Authentication.AuthenticationException ex)
           {
               client.Close();
           }
           catch (Exception ex)
           {
               lblenc.Text = ex.Message;
               client.Close();
           }

推荐答案

如果你发现错误,你会发现有很多可能的原因。您需要解决可能的原因,直到找到导致它的原因。您必须自行解决此问题。
If you google the error you'll find that there are many possible reasons for this. You'll need to work through the possible reasons until you find the one causing it. You'll have to troubleshoot this on your own.


这篇关于从ASP.NET C向iOS发送通知时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆