I am creating a chatting app using WCF-Duplex and WPF. Is there is any way to call a UI function when the callback method (which is in another class than the UI) is invoked from the server?!
Here is a sample of my classes:
Service:
[ServiceContract(
Name = "GPH_QuickMessageService",
Namespace = "TextChat",
SessionMode = SessionMode.Required,
CallbackContract = typeof(IMessageServiceCallback))]
public interface IMessageServiceInbound
{
[OperationContract]
int JoinTheConversation(string userName);
} public interface IMessageServiceCallback
{
[OperationContract(IsOneWay = true)]
void NotifyUserJoinedTheConversation(string userName);
}
The JoinTheConversation invokes NotifyUserJoinedTheConversation method at the client
The Client: The Form:
public partial class Account : Window
{
public Account()
{
InitializeComponent();
}
public void updateUsersInConversation(string username)
{
TreeViewItem item = new TreeViewItem();
item.Header = username;
contactsTree.Children.Add(item);
}
}
The callback implementation at the client
[CallbackBehavior(UseSynchronizationContext = false)]
public class ChatCallBack : GPH_QuickMessageServiceCallback, IDisposable
{
public ChatCallBack()
{
//UIContext = context;
}
public void NotifyUserJoinedTheConversation(string userName)
{
MessageBox.Show("IN CLIENT");
//I want to call updateUsersInConversation in the UI class
}
}
I searched alot and found a lot of things about delegation and SendOrPostCallBack but I just couldn't link all these things together. I am sorry for the long post and hope anyone can help me with that