-1

http(s) を介して外部リソースで同期要求を行うアプリケーションがあります。数週間ごとに、次の例外が発生します

Exception: System.Net.WebException - Message: Unable to connect to the remote server

内部例外: System.Net.Sockets.SocketException - メッセージ: 接続先が一定期間後に適切に応答しなかったため、接続の試行が失敗したか、接続されたホストが応答しなかったために確立された接続が失敗しました

私を悩ませているのは、トレース ログが、この例外のすべてのインスタンスに対して、リクエストに "21 秒" スローされたことを示していることです。

以前にこのような動作を見た人はいますか?解決策はありますか? System.Net.HttpWebRequest 名前空間内に既知の問題はありますか? System.Net.HttpWebRequest を使用するためのベスト プラクティスは何ですか。たとえば、応答ストリームを明示的に閉じて破棄する必要があります...

4

1 に答える 1

0

If you're accessing external resources, the answer is most likely that those resources weren't available (their servers were down, your connection was down, their connection was down, etc).

You can set the .Timeout property before the GetResponse() method of the HTTPWebRequest object to extend the time before it officially times out and see what happens:

myHttpWebRequest.Timeout = 10; //In milliseconds

Failing this, you could try adding this to your configuration file if your running ASP.NET with NETWORK SERVICE as your host account:

<configuration >
  <system.net>
    <defaultProxy>
      <proxy bypassonlocal="true" usesystemdefault="false" />
    </defaultProxy>
</system.net>
</configuration>

If you don't, your application can't get to the proxy settings. .NET search for it, can't find it and then connects via default. This will cause the exception but the excution will continue. It may explain why it's always 21 seconds into a request.

Read the full details here.

于 2009-09-02T10:27:12.580 に答える