Click here to Skip to main content
15,921,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been programming in C #, WCF.
Video with the error: http://screencast-o-matic.com/watch/cleI1kBcg

How to disconnect a user if an error occurs in connection? Below I have written exceptions that occur in the output:

The first stage of processing an exception of type "System.ServiceModel.CommunicationException" in the application System.ServiceModel.dll
The first stage of processing an exception of type "System.ServiceModel.CommunicationException" in the application System.ServiceModel.dll
"Server.vshost.exe" (Managed (v4.0.30319)): Uploaded
Stream <Anonymous> '(0xd3c) has exited with code 0 (0x0).
The first stage of processing an exception of type "System.ServiceModel.CommunicationException" in the application System.Runtime.DurableInstancing.dll
The first stage of processing an exception of type "System.ServiceModel.CommunicationException" in the application System.Runtime.DurableInstancing.dll


the server is not terminated and is not interrupted.
Below I have written the source code for a server connection.

C#
   [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
    ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
    public class ChatService : IChat
    {
        Dictionary<Client, IChatCallback> clients = new Dictionary<Client, IChatCallback>();

        List<Client> clientList = new List<Client>();

         public IChatCallback CurrentCallback
         {
             get
             {
                 return OperationContext.Current.GetCallbackChannel<IChatCallback>();
             }
         }

        object syncObj = new object();

        public bool Connect(Client client)
        {
            if (SearchClientsByName(client.Name) && !clients.ContainsValue(CurrentCallback))
            {
                OperationContext.Current.Channel.Faulted += new EventHandler(delegate{Console.WriteLine("User Error (faulted)" + client.Name);});
                OperationContext.Current.Channel.Closed += new EventHandler(delegate { Console.WriteLine("User Error (closed)" + client.Name); });

/* bla bla bla */
        }
/* bla bla bla */


I also recorded a video for you to understand exactly the problem.
Thank you!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900