Windows Phone使用证书进行加密推送,服务端发送消息时的相关问题
最近在研究Windows Phone的推送通知功能,一般的无加密推送已经测试通过,但是在加入SSL加密推送时,总是出现问题无法推送成功。具体问题如下:在手机端方面已经上传证书到微软账号中,并成功申请到加密的通道;服务端这边是WinForm程序,在代码中引用了已经上传好的证书,但发送请求的时候总是被拒绝,说是没有提供的证书没有权限访问相关通道。跪求大神帮忙解释!!
服务端发送消息的代码:
public static string SendToast(string toUri, string title, string content, string jumpToPage = "/Page1.xaml")
{
try
{
var request = (HttpWebRequest)WebRequest.Create(toUri);
string toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>" + title + "</wp:Text1>" +
"<wp:Text2>" + content + "</wp:Text2>" +
"<wp:Param>" + jumpToPage + "</wp:Param>" +
"</wp:Toast> " +
"</wp:Notification>";
var byteMessage = Encoding.UTF8.GetBytes(toastMessage);
request.ContentLength = byteMessage.Length;
//下面这行加载证书
request.ClientCertificates.Add(new X509Certificate(@"D:\MyProjects\Demo\ToastSendAndReceive\Server\Server\ToastKey\win-push_intsig_net.cer"));
request.Method = "POST";
request.ContentType = "text/xml";
request.Headers.Add("X-WindowsPhone-Target", "toast");
request.Headers.Add("X-NotificationClass", "2");
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(byteMessage, 0, byteMessage.Length);
}
//接收回复信息
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string notificationStatus = response.Headers["X-NotificationStatus"];
string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
return notificationStatus + " | " + deviceConnectionStatus + " | " +
notificationChannelStatus;
}
catch (Exception ex)
{
if (ex is WebException)
{
var webEx = ex as WebException;
string exceptionStr = "Header:"+Environment.NewLine;
foreach (string key in webEx.Response.Headers)
{
exceptionStr += key + ", " + webEx.Response.Headers[key] + Environment.NewLine;
}
var stream = webEx.Response.GetResponseStream();
if (stream != null)
{
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
exceptionStr += "body: "+Environment.NewLine + s;
}
return exceptionStr;
}
return "Exception caught sending update: " + ex.Message;
}
下面为返回的错误信息:
Header:Windows Phone 服务端 证书 SSL加密推送 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 求高人解答 别沉贴啊 --------------------编程问答-------------------- 这个比较复杂了,这么多代码。。。。,要说出问题点,才好回答 --------------------编程问答--------------------
Content-Length, 1233
Content-Type, text/html
Date, Tue, 12 Nov 2013 09:29:28 GMT
Server, Microsoft-IIS/7.5
X-Powered-By, ASP.NET
body:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>403 - Forbidden: Access is denied.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
<div class="content-container"><fieldset>
<h2>403 - Forbidden: Access is denied.</h2>
<h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3>
</fieldset></div>
</div>
</body>
</html>
问题点就是 Windows Phone要怎么做到使用证书来进行加密推送
补充:移动开发 , Windows Phone