我在等待使用Aero Gear .Net client發送推送通知的呼叫。呼叫推送的返回值是System.Net.HttpStatusCode
。推送成功的預期代碼是「已接受」。如何解決等待調用HttpStatusCode的中止請求?
但是當我等待調用SendPushNotification方法,從方法返回前HttpStatusCode在這條線,它拋出一個"The request was aborted. The connection was closed unexpectedly"
錯誤:
System.Net.HttpStatusCode status = await client.Send(unifiedMessage);
標誌着我來自控制器的召集對推方法async,並添加了等待在哪裏有一個異步方法的調用。
問:
你怎麼能解決在等待調用HttpStatusCode中止請求嗎?
這是呼叫的要旨從初始呼叫在控制器到推類方法流下:
控制器:
//In Controller Post action that calls SendPushNotification
[HttpPost]
public async Task<ActionResult> Index(Order exec_order)
{
try
{
//Send a push notification with the order details
try
{
MyLogger.FileLogger.Info("Before Push Notification");
System.Net.HttpStatusCode status = await PushsClassLibrary.PushNotification.SendPushNotification(exec_order.Application", "Order Summary");
MyLogger.FileLogger.Info("Push Notification Status: " + status);
}
catch (Exception ex) //request aborted error caught here
{
MyLogger.FileLogger.Error("Push Notification Exception -" + ex.Message);
}
}
推送類:
//In PushNotification class containing SendPushNotification
public static async Task<System.Net.HttpStatusCode> SendPushNotification(string messageToPush, string serviceName)
{
string[] listUsers = users.ToArray();
unifiedMessage.criteria.alias = listUsers;
System.Net.HttpStatusCode status = await client.Send(unifiedMessage);
return status;
}
你確定你的方法'SendPushNotification()'不會拋出任何異常嗎? – Rahul