我正在等待使用Aero Gear .Net 客户端发送推送通知的电话。调用 push 的返回值是 a System.Net.HttpStatusCode
。如果推送成功,预期的代码是“已接受”。
但是当我等待对 SendPushNotification 方法的调用时,它会"The request was aborted. The connection was closed unexpectedly"
在从该方法返回 HttpStatusCode 之前抛出一个错误:
System.Net.HttpStatusCode status = await client.Send(unifiedMessage);
我将控制器对 push 方法的调用标记为异步,并在调用异步方法的地方添加了 await。
问题:
您如何解决等待调用 HttpStatusCode 时中止的请求?
这是从控制器中的初始调用到 push 类方法的调用要点:
控制器:
//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;
}