0

Aero Gear .Net クライアントを使用してプッシュ通知を送信するための呼び出しを待っています。push の呼び出しからの戻り値はSystem.Net.HttpStatusCode. プッシュが成功した場合に期待されるコードは「Accepted」です。

しかし、SendPushNotification メソッドの呼び出しを待機すると、"The request was aborted. The connection was closed unexpectedly"次の行のメソッドから HttpStatusCode が返される前にエラーがスローされます。

System.Net.HttpStatusCode status = await client.Send(unifiedMessage);    

コントローラーからプッシュ メソッドまでの呼び出しを非同期としてマークし、非同期メソッドの呼び出しがあった場所に await を追加しました。

質問:

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;
}
4

1 に答える 1

1

確認したいステータスコードはHttpStatusCode.OK次のとおりだと思います。「リクエストは中止されました。接続は予期せず閉じられました」というエラーが例外であると確信しています。AeroGear サーバーが実行中であり、PushsClassLibrary.

それ以外の場合は、AeroGear プロジェクトにも、使用できるC# センダー ライブラリがあります。

于 2016-08-11T15:25:19.317 に答える