Search code examples
c#wpfwcf

How to route Button events from a WPF application to a wcf service


I have a wcf service hosted in a wpf application. I also have a multiple remote clients which are communicating with the service without any problems.

I want to know how to get hold of the service instance from WPF application.

I'm trying to use the IClientCallback returned from OperationContext.Current.GetCallbackChannel<IClientCallback>() to make a call to the operations on the client side when a button is pressed in the WPF application.

The InstanceContextMode = InstanceContextMode.Single on the service side if this helps. Please show me through a code example as I'm new to WCF.


Solution

  • I figured it out by myself. I had to use the one of the overloaded constructors of servicehost and pass in the class holding the data contracts.

    public ServiceHost(
    object singletonInstance,
    params Uri[] baseAddresses