开发者

How can a client try to reconnect to a server after a first failed try with WCF?

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 (Endpo开发者_开发问答intNotFoundException). 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.


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); 
        } 
    } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜