Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET WCF Chat Client
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.
 
[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 12-Mar-12 1:25am
Jinfaa491
Comments
BobJanova at 12-Mar-12 9:00am
   
What exception?
Do you get an exception in the server as well?
Jinfaa at 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
GanesanSenthilvel at 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 at 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
0 Sergey Alexandrovich Kryukov 470
1 mhegazy94 460
2 Ravi Bhavnani 190
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,135
1 OriginalGriff 6,801
2 CPallini 5,350
3 George Jonsson 3,619
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 12 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100