在第一次尝试使用 WCF 失败后,客户端如何尝试重新连接到服务器?

发布于 2024-09-02 10:19:56 字数 308 浏览 3 评论 0原文

我正在使用客户端-服务器应用程序。当客户端启动时,他会看到一个登录屏幕。当服务器尚未启动时,对服务器的调用将引发我捕获的异常(EndpointNotFoundException)。我显示一个消息框,告诉用户服务器已离线。当他尝试再次重新连接时,即使服务器在线,也会抛出另一个异常(CommunicationObjectFaultedException)。当新的客户端启动时,他就可以连接到服务器。但之前尝试过的客户端仍然会收到错误。

我现在的问题是,第一个客户端在第一次尝试失败后如何登录,而不必再次启动他的程序。所以我想清除通信通道的故障状态或类似的情况。

提前致谢。

I'm using a client - server app. When a client starts, he gets a login-screen. When the server is not up yet, the call to the server will throw an exception which i catch (EndpointNotFoundException). I show a messagebox telling the user the server is offline. When he tries to reconnect again, it will throw another exception (CommunicationObjectFaultedException), even though the server is online. When a new client starts then, he can connect to the server. But the client who attempted before, still gets the error.

My question now is how can the first client login after a failed first try without having to start his program again. So i want to clear the communicationchannel of its faulted state or something like that.

Thanks in advance.

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

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

发布评论

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

评论(1

遗弃M 2024-09-09 10:19:56

基本上,您必须在 EndpointNotFoundException 处理程序中调用 Abort这里有一篇文章解释了原因。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication1.ServiceReference1; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            Service1Client Proxy = null; 
            try 
            { 
                Proxy = new Service1Client(); 
                string res = Proxy.GetData(); 
                Console.WriteLine(res); 
                Proxy.Close();       
            } 
            catch (EndpointNotFoundException)
            { 
                Proxy.Abort(); 
            } 
            Console.ReadKey(true); 
        } 
    } 
}

Basically, you have to call Abort in the EndpointNotFoundException handler. Here is an article that explains the reasoning.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication1.ServiceReference1; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            Service1Client Proxy = null; 
            try 
            { 
                Proxy = new Service1Client(); 
                string res = Proxy.GetData(); 
                Console.WriteLine(res); 
                Proxy.Close();       
            } 
            catch (EndpointNotFoundException)
            { 
                Proxy.Abort(); 
            } 
            Console.ReadKey(true); 
        } 
    } 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文