Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
There is a problem in the server's WCF. If I close client is side through the "ctrl + alt + del" then all the users connected to the server to get an exception. After that you can not connect. I took as a basis for this program Client-server app[^]. The comments also wrote about this problem.

The author can not help ... Do not know how to get around the problem. The only wrote the code and that does not apply to this task.

C#
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService
{
    #region Feilds

    private static object syncObj = new object();
    private static Dictionary<IContextChannel, string> _users = new Dictionary<IContextChannel, string>();

    #endregion

    #region Properties

    public IContextChannel CurrentUserChannel { get { return OperationContext.Current.Channel; } }
    public string CurrentUserName
    {
        get
        {
            return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
        }
    }

    #endregion

    #region IMyService Members

    public void Connect()
    {
        lock (syncObj)
        {
            if (_users.ContainsValue(CurrentUserName))
            {
                _users.Remove(CurrentUserChannel);
            }
            _users.Add(CurrentUserChannel, CurrentUserName);
        }

        CurrentUserChannel.Faulted += new EventHandler(CurrentUserChannel_Faulted);
        CurrentUserChannel.Closing += new EventHandler(CurrentUserChannel_Closing);
    }

    #endregion

    #region Connection Handling

    void CurrentUserChannel_Closing(object sender, EventArgs e)
    {
        HandleChannel(sender as IContextChannel);
    }
    void CurrentUserChannel_Faulted(object sender, EventArgs e)
    {
        HandleChannel(sender as IContextChannel);
    }
    private void HandleChannel(IContextChannel channel)
    {
        if (channel.State == CommunicationState.Closing || channel.State == CommunicationState.Faulted)
        {

            lock (syncObj)
            {
                if (_users.ContainsKey(channel))
                {
                    _users.Remove(channel);
                }
            }
        }
    }

    #endregion

Need the help of professionals. How do I convert an existing source code for the server? Here's the code:
http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=25261&zep=WCFWPFApp/ServiceAssembly/ChatService.cs&rzp=/KB/IP/WCFWPFChatRoot//wcfwpfapp.zip
Posted
Comments
BobJanova 12-Mar-12 9:00am    
What exception?
Do you get an exception in the server as well?
Jinfaa 12-Mar-12 9:03am    
The first stage of processing an exception of type "System.TimeoutException" in Appendix mscorlib.dll
The first stage of processing an exception of type "System.TimeoutException" in Appendix System.ServiceModel.dll
The first stage of processing an exception of type "System.ServiceModel.CommunicationObjectAbortedException" in Appendix System.ServiceModel.dll
The first stage of processing an exception of type "System.ServiceModel.CommunicationException" in Appendix System.Runtime.DurableInstancing.dll
The first stage of processing an exception of type "System.ServiceModel.CommunicationObjectAbortedException" in Appendix System.ServiceModel.dll
The first stage of processing an exception of type "System.ServiceModel.CommunicationException" in Appendix System.ServiceModel.dll
The first stage of processing an exception of type "System.ServiceModel.CommunicationObjectAbortedException" in Appendix System.ServiceModel.dll
The first stage of processing an exception of type "System.ServiceModel.CommunicationObjectAbortedException" in Appendix System.Runtime.DurableInstancing.dll
The first stage of processing an exception of type "System.Net.Sockets.SocketException" in System.dll application
The first stage of processing an exception of type "System.ServiceModel.CommunicationException" in Appendix System.ServiceModel.dll
Ganesan Senthilvel 12-Mar-12 11:10am    
Looks like it is the custom control from Islam and it is the open issue. What is the response?
Jinfaa 12-Mar-12 11:16am    
Thank you for your reply! Asked a similar question http://idemery.net/2008/05/28/wcf-serverclient-chat-sample/#comment-40. But this source code, I do not know how to apply. For this program. The author had disappeared.

To test I run two clients. And a finish through the Task Manager.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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