I'm awaiting a call to send a push notification using the Aero Gear .Net client. The return value from the call to push is a System.Net.HttpStatusCode
. The expected code if the push is successful is "Accepted".
But when I await the call to the SendPushNotification method, it throws a "The request was aborted. The connection was closed unexpectedly"
error before the HttpStatusCode is returned from the method at this line:
System.Net.HttpStatusCode status = await client.Send(unifiedMessage);
I marked the call from the controller up to the push method as async, and added await where there was a call to an async method.
Question:
How can you resolve an aborted request on awaited call to HttpStatusCode?
This is a gist of the call trickled down from the initial call in the controller to the push class method:
Controller:
//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);
}
}
Push Class:
//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;
}
I think that status code you will want to check is HttpStatusCode.OK
and I'm pretty sure that the error you get: "The request was aborted. The connection was closed unexpectedly" is an exception. Are you sure that the AeroGear server is running and that you don't need Proxy configuration for your PushsClassLibrary
?
Otherwise the AeroGear Project also has a C# sender library that you could use.