Sto tentando di scrivere un server push per l'iPhone in C#. Ho il seguente codice:C# server push di iPhone?
// Create a TCP/IP client socket.
using (TcpClient client = new TcpClient())
{
client.Connect("gateway.sandbox.push.apple.com", 2195);
using (NetworkStream networkStream = client.GetStream())
{
Console.WriteLine("Client connected.");
X509Certificate clientCertificate = new X509Certificate(@"certfile.p12", passwordHere);
X509CertificateCollection clientCertificateCollection = new X509CertificateCollection(new X509Certificate[1] { clientCertificate });
// Create an SSL stream that will close the client's stream.
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
null
);
try
{
sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com");
}
catch (AuthenticationException e)
{
Console.WriteLine("Exception: {0}", e.Message);
if (e.InnerException != null)
{
Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
}
Console.WriteLine("Authentication failed - closing the connection.");
client.Close();
return;
}
}
ect ....
Solo Continuo a ricevere un'eccezione: "Una chiamata a SSPI non è riuscita, vedere Eccezione interna" interno Eccezione -> "Il messaggio ricevuto era inaspettato o mal formattato. "
Qualcuno ha qualche idea di cosa sta andando storto qui?
Capito. Sostituito sslStream.AuthenticateAsClient ("gateway.sandbox.push.apple.com"); con sslStream.AuthenticateAsClient ("gateway.sandbox.push.apple.com", clientCertificateCollection, SslProtocols.Default, false); E registrato i certificati sul PC. – Kyle
Ha funzionato per te? – Zanoni
Sì, ho tutto a posto e posso inviare messaggi al mio iPhone. Non dimenticare di registrare il tuo file .p12 con Windows. – Kyle