0

これはおそらくばかげた質問であり、明らかな何かが欠けているだけです。Web エラーの処理などについて調べてみましたが、なぜこれが起こっているのかについての答えが見つからないようです。

基本的に、私が呼び出しているサーバーはjsonを送信して送り返しますが、リクエストに断続的な問題があります-つまり、502 BadGateway-他にはありません。断続的と言うときは、5 時間以上失敗することなく 200 のリクエストに対して完全に機能し、その後 502 をスローする可能性があることを強調しますが、最初のリクエストでも発生する可能性があります。予測が難しい。また、サーバーにはアクセスできないことに注意してください。これは構成などです。完全にリモート。

開発環境では、例外を処理し続けることができ、プログラムは引き続き実行され、同じ要求を使用して同じサーバーに対して、次の要求で、正常に処理される 502 を受信しない場合があります。ただし、開発プラットフォームから離れたスタンドアロンでは、例外データなしでハード クラッシュが発生します。

私は、try/catch を動かして、問題の呼び出しをコードの残りの部分から分離し、それを組み合わせることなどを試みましたが、常に同じ問題を受け取りました。

遅れており、おそらく正しく処理していないため、ガイダンスをいただければ幸いです。私は今夜​​これをあきらめることを拒否しています. 私がただのスクラブで、新鮮な目で見ていたとしたら、笑って私を呼んでください。

前もって感謝します

ps。getResponse() で例外が発行されています

try
        { 
            using (HttpWebResponse inboundResponse = (HttpWebResponse)outboundRequest.GetResponse()) //exception here for 502
            using (StreamReader stream = new StreamReader(inboundResponse.GetResponseStream()))
            using (JsonTextReader reader = new JsonTextReader(stream))
            {
                List<T> outputData = new List<T>();
                while (reader.Read())
                {
                    JsonSerializer serializer = new JsonSerializer();
                    var tempData = serializer.Deserialize<T>(reader);
                    outputData.Add(tempData);
                }
                inboundResponse.Close();
                return outputData;
            }
        }
        catch (WebException e)
        {
            if (e.Status == WebExceptionStatus.ProtocolError)
            {
                UIController.addSystemMessageToChat("Protocol Error");
                switch(((HttpWebResponse)e.Response).StatusCode)
                {
                    case HttpStatusCode.BadGateway:
                        UIController.addSystemMessageToChat("Resending Response");
                        //process exception
                    default:
                        throw;
                }
            }

        }
4

1 に答える 1

1

ではないかもしれませんWebException

Exceptionハンドラーにキャッチを追加してみてください。

try
{ 
    using (HttpWebResponse inboundResponse = (HttpWebResponse)outboundRequest.GetResponse()) //exception here for 502
    using (StreamReader stream = new StreamReader(inboundResponse.GetResponseStream()))
    using (JsonTextReader reader = new JsonTextReader(stream))
    {
        List<T> outputData = new List<T>();
        while (reader.Read())
        {
            JsonSerializer serializer = new JsonSerializer();
            var tempData = serializer.Deserialize<T>(reader);
            outputData.Add(tempData);
        }
        inboundResponse.Close();
        return outputData;
    }
}
catch (WebException e)
{
    if (e.Status == WebExceptionStatus.ProtocolError)
    {
        UIController.addSystemMessageToChat("Protocol Error");
        switch(((HttpWebResponse)e.Response).StatusCode)
        {
            case HttpStatusCode.BadGateway:
                UIController.addSystemMessageToChat("Resending Response");
                //process exception
            default:
                throw;
        }
    }

}
catch (Exception e)
{
    // catch and handle an unknown / unexpected exception type
}
于 2016-01-12T13:05:22.690 に答える