.net Remoting:检测服务器是否未运行

发布于 2024-09-12 16:15:38 字数 868 浏览 4 评论 0原文

我正在开发一个使用 .net 远程处理 IPC 的应用程序。

当我的客户端应用程序启动时,它使用以下代码连接到服务器:

  chnl = gcnew HttpChannel();
  ChannelServices::RegisterChannel(chnl, false);      
  IPCObjectInstance = (BaseRemoteObject)Activator.GetObject(
     typeof(BaseRemoteObject),
     "http://localhost:1237/MyRemoteObject.soap");

并且,当我进行函数调用时,我使用以下代码:

  BaseRemoteObject.GetFileTextDelegate svd = new BaseRemoteObject.GetFileTextDelegate(IPCObjectInstance, BaseRemoteObject.GetFileText);
  AsyncCallback  callback  = new AsyncCallback(this, &ClientGUI.RecievedStringText);
  IAsyncResult  arValSet  = svd.BeginInvoke(callback, null);

该代码按原样工作很好。但是,我希望我的客户端在启动时检测服务器是否正在运行,并显示相应的错误消息。

当服务器未运行时,客户端会等待大约 3 秒,然后抛出 Web 异常(如底部所示)。没有错误“位置”,所以我不确定将 try\catch 块放在哪里。

检测我的服务器未运行的最佳方法是什么?

谢谢!

I'm working on an app that uses .net remoting for IPC.

When my client app starts up, it uses the following code to connect to the server:

  chnl = gcnew HttpChannel();
  ChannelServices::RegisterChannel(chnl, false);      
  IPCObjectInstance = (BaseRemoteObject)Activator.GetObject(
     typeof(BaseRemoteObject),
     "http://localhost:1237/MyRemoteObject.soap");

And, when I make my function call, I use the following code:

  BaseRemoteObject.GetFileTextDelegate svd = new BaseRemoteObject.GetFileTextDelegate(IPCObjectInstance, BaseRemoteObject.GetFileText);
  AsyncCallback  callback  = new AsyncCallback(this, &ClientGUI.RecievedStringText);
  IAsyncResult  arValSet  = svd.BeginInvoke(callback, null);

This code works great as is. However, I want my client to detect whether or not the server is running when it boots, and display the appropriate error message.

When the server isn't running, the client waits for about 3 seconds, before throwing a web exception (shown at bottom). There is no error "location", so I'm not sure of where to put the try\catch block.

What is the best way to detect my server not running?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅紫色的梦幻 2024-09-19 16:15:38

它应该可以在 BeginInvoke 行周围执行 try/catch。

但我的建议是创建一个 Status 方法,您可以同步调用该方法而不是异步调用,并在该调用周围进行 try/catch 操作。它可以是一个什么都不做的虚拟方法。

还可以在指定端口上打开到远程服务器的 tcp 连接,并查看是否获得连接。但这很像围绕远程调用的 try/catch。

It should work to do a try/catch around your BeginInvoke line.

But my suggestion would be to create a Status method which you call synchrously instead of async, and do try/catch around that call instead. It can be a dummy method doing nothing.

It also possible to open a tcp connection to the remote server on the port specified and see if you get a connection. But this would be much like try/catch around a remoting call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文