executer

executer

  • NA
  • 1
  • 13k

wcf p2p messenger

Jan 7 2011 11:21 AM
I'm building a WCF messenger which will provide the users a list of their friends and they could communicate with their friends in p2p. That means that each user that is connected to the server, hosts a new service of his own for other users in case they want to communicate with him.

If a user wants to communicate with another, he opens a new channel to his service, and the other user identifies his session creation attempt and opens a new callback channel to him. the callback interface and the service interface is the same by the way.

Anyways, my code does not work properly. The user host can send messages to other users using the callback channel but when the other side (which is the "client" in that case) tries to, the server gets it but complains that:
OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] doesn't exist.
I actually think that the whole OperationContext.Current is damaged.

The code:
When a user hosts his own service:
            clientService = new ServiceHost(typeof(ClientEvents));
clientService.AddServiceEndpoint(typeof(ChatService.IClientEvents), tcpbind, myHost);
clientService.Open();


Service side (which works actually when sending messages, but not when receiving them properly) when saving the callback channel:
 
ChatService.IClientEvents usrcbChnl = OperationContext.Currect.GetCallbackChannel<ChatService.IClientEvents>();


Client side when initiaties a new connection:

                     callbacks.Add(usr, new ClientEvents()); // callbacks is a dictionary that holds new user connections and their callback

NetTcpBinding tcpbind = new NetTcpBinding();
tcpbind.Security.Mode = SecurityMode.None;
ChatService.IClientEvents frCb = DuplexChannelFactory.CreateChannel(this.callbacks[usr], tcpbind, new EndpointAddress(usr.PeerHost));


Now when this user client tries to send and use the callback channel, the server does receive the message but OperationContext is damaged.

Thanks in advance!