我试图在C#中为iPhone编写推送服务器。我有以下代码:C#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 ....
只有我不断收到一个例外: “到SSPI调用失败,请参见内部异常” 内部异常 - >“收到的消息出乎意料或格式不正确。“
有没有人有任何想法这里怎么了?
想通了。替换为 sslStream.AuthenticateAsClient(“gateway.sandbox.push.apple.com”); with sslStream.AuthenticateAsClient(“gateway.sandbox.push.apple.com”,clientCertificateCollection,SslProtocols.Default,false); 并在PC上注册证书。 – Kyle 2009-06-29 00:15:37
它适合你吗? – Zanoni 2009-07-03 17:10:14
是的,我有一切工作,并可以推送消息到我的iPhone。不要忘记用windows注册你的.p12文件。 – Kyle 2009-07-06 22:26:02