リモート処理のクライアントタイムアウト時間 − Insider.NET − @IT

http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=4241&forum=7
NothingButXMLInfoSetさんの回答。

チャネルは何を使っていますか?HttpChannelであれば、2つの方法でタイムアウトを設定できます。
1) SOAPSUDS.EXEでプロキシを作っている場合は、そのプロキシにTimeoutプロパティがあるので、ms単位のタイムアウトまでの時間を設定できます。
2) Activator.GetObject(またはconfig)などを使っている場合は、次のコードでTimeoutプロパティにアクセスできます。

コード:

                                                                                                                                                              • -


Remote rem = (Remote)Activator.GetObject(typeof(Remote), "http://localhost:82/Remote.rem");
System.Collections.IDictionary props = ChannelServices.GetChannelSinkProperties(rem);
props["Timeout"] = 1000;


unibon が遭遇した事象だと、おおよそ10分ほど放っておくと、サーバー側のほうでエラーが起こる。エラー内容は、つぎのようにサーバーからクライアントにイベントが投げられないというものだ。

System.Runtime.Remoting.RemotingException: 要求されたサービスが見つかりません

Server stack trace:
場所 System.Runtime.Remoting.Channels.SoapServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)

Exception rethrown at [0]:
場所 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
場所 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
場所 RemotingServerClient.CallbackSink.HandleToClient(CommsInfo info)
場所 RemotingServerClient.ServerTalk.RaiseHostToClient(Int32 sequence, String packet) 場所 C:\Projects\RemotingServer\ServerClient\ServerTalk.cs:行 33
場所 RemotingServerClient.ServerForm.processDownlinkQueue() 場所 C:\Projects\RemotingServer\RemotingServer\ServerForm.cs:行 103
場所 RemotingServerClient.ServerForm.processDownlinkTimer_Elapsed(Object sender, EventArgs e) 場所 C:\Projects\RemotingServer\RemotingServer\ServerForm.cs:行 211
場所 RemotingServerClient.SimpleTimer.innerTimer_Tick(Object sender, EventArgs e) 場所 C:\Projects\RemotingServer\RemotingServer\Tools\SimpleTimer.cs:行 123
場所 System.Windows.Forms.Timer.OnTick(EventArgs e)
場所 System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
場所 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

このタイムアウトの設定をサーバー側でおこなうとこれが回避できる。ちなみに無限は -1 だ。
http://msdn.microsoft.com/ja-jp/library/system.runtime.remoting.channels.http.httpchannel(VS.71).aspx


なお、クライアント側に設定しても効かないようだ。