Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. WCF service - is CallBackChannel alive

WCF service - is CallBackChannel alive

Scheduled Pinned Locked Moved WCF and WF
questioncsharpwcfgame-devsysadmin
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hanzaplast
    wrote on last edited by
    #1

    hi guys, this seems to be easy, but i just cant find right answer. i have WCF duplex service to host online poker game (silverlight on client). if one client plug of his cable or meteor strikes at his home i need to disconnect him. it is easy to implement method Disconnect, but i cant call it if user is unsuspectedly disconnected... my approach is: 1. enter - open page 2. connect - client calls method Connect wich is OperationContract on server; server have array field of all connected clients - CallbackContract 3. do something - send to server your move (irrelevant logic for this question) 4. check clients - this is what i dont have. i want to remove disconected users from my array field of all connected clients 5. recive info - server says what happend to all clients via CallbackContract OperationContext.Current.Channel.Closed and OperationContext.Current.Channel.Faulted sounds like what i need, but they act strange?

    public class Poker : IPokerService
    {
    HttpContext appContext;

        HttpContext AppContext
        {
            get
            {
                if(appContext == null)
                    appContext = HttpContext.Current;
                return appContext;
            }
        }
        Dictionary<string, IPokerClient> ClientList
        {
            get
            {
                object temp = AppContext.Application\["ClientList"\];
                if (temp == null)
                {
                    temp = new Dictionary<string, IPokerClient>();
                    AppContext.Application\["ClientList"\] = temp;
                }
                return (Dictionary<string, IPokerClient>)temp;
            }
        }
    public void Connect(string id)
        {
            Dictionary<string, IPokerClient> clientList = ClientList;
            try
            {
                IPokerClient client = OperationContext.Current.GetCallbackChannel<IPokerClient>();
                if (!clientList.ContainsKey(id))
                    clientList.Add(id, client);
                else
                    clientList\[id\] = client;
                OperationContext.Current.Channel.Faulted += new EventHandler(Channel\_Faulted);
                OperationContext.Current.Channel.Closed += new EventHandler(Channel\_Closed);
            }
            catch
            {
                //later
            }
        }
    void Channel\_Closed(object sender, EventArgs e)
        {
        }
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups