この質問が以前に尋ねられたことは知っていますが、どれも役に立たないようです。
asp.net アプリケーションからプッシュ通知を送信しようとしていますが、次のエラーが表示されます。
"A call to SSPI failed, see inner exception." System.Exception {System.Security.Authentication.AuthenticationException}
"The message received was unexpected or badly formatted" System.Exception {System.ComponentModel.Win32Exception}
コードは次のとおりです。
int port = 2195;
String hostname = "gateway.sandbox.push.apple.com";
//load certificate
string certificatePath = HostingEnvironment.ApplicationPhysicalPath + "cert.pem";
string certificatePassword = "xxxxxxx";
X509Certificate2 clientCertificate = new X509Certificate2(certificatePath, certificatePassword);
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
TcpClient client = new TcpClient(hostname, port);
SslStream sslStream = new SslStream(
client.GetStream(),
false,
null,
null
);
try
{
sslStream.AuthenticateAsClient(hostname, certificatesCollection, System.Security.Authentication.SslProtocols.Tls, false);
}
catch (AuthenticationException ex)
{
client.Close();
}
// 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)
String deviceId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
writer.Write((deviceId.ToUpper().ToArray()));
String payload = "{\"aps\":{\"alert\":\"Test\",\"badge\":14}}";
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();
sslStream.Write(array);
sslStream.Flush();
// Close the client connection.
client.Close();
証明書に問題がありますか、それともなぜこの問題が発生する可能性がありますか?
p12ファイルを使用することになっていますか? もしそうなら、.pem ファイルがある場合、どうすれば p12 ファイルを取得できますか?
これを Windows で開発していますが、Windows のどこかに証明書を登録する必要がありますか?
よろしく、マリウス。