views:

117

answers:

1

Hey guys,

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.

A: 

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); 
        } 
    } 
}
mafutrct
I cannot do this. My proxy class is singleton design pattern, and just calling the abort like this "ServiceConnector.ServiceConnector.SingletonServiceConnector.Proxy.Abort();" isn't working either, as i expected.
djerry
I don't see why you should not be able to call Abort. The example code I provided is surely not applicable, but the general idea (try - connect, catch - Abort) should still work. There is no need to instantiate the proxy in the try as in the example code, you can of course instantiate it elsewhere as a singleton!
mafutrct