本文介绍了托管后推送通知不会转到iOS设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想发送推送通知以使用WCF服务发送ios设备。
当我从本地计算机运行服务时,推送通知将发送到服务器
但当它在iis上托管时,通知不会发送。
i我收到以下错误:
error : -
I want to send the Push notification to send ios device using WCF service.
When i run the service from Local Machine the push notification is send to the server
but when it is hosted on iis notification is not send.
i am receiving following error:
error:-
A call to SSPI failed, see inner exception
内部异常:
inner exception:
System.ComponentModel.Win32Exception " +
"(0x80004005): The message received was unexpected or badly formatted
什么我试过了:
What I have tried:
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;
}
}
推荐答案
这篇关于托管后推送通知不会转到iOS设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!