I have to communicate 2 WPF application.
To communicate, i am using a WCF windows service running on local machine.
When one of then calls a method on service, service calls back to other one. There is just one callback interface and all methods are written in it. But, 2 WPF apps are not using same callback methods. So, i am forced to implement unused methods.
So, I am tried to find if i can set 2 different and independent callback interfaces on service, but i couldn’t. Is there any way to do it?
UPDATE
My sample code:
IDeviceCallBack
public interface ITestCallBack1
{
[OperationContract(IsOneWay = true)]
void Test1();
}
public interface ITestCallBack2
{
[OperationContract(IsOneWay = true)]
void Test2();
}
public interface IDeviceCallback : ITestCallBack1, ITestCallBack2
{ }
IDevice
[ServiceContract(CallbackContract = typeof(ITestCallBack1))]
public interface ITestContract1
{ }
[ServiceContract(CallbackContract = typeof(ITestCallBack2))]
public interface ITestContract2
{ }
[ServiceContract(CallbackContract = typeof(IDeviceCallback))]
public interface IDevice : ITestContract1, ITestContract2
{
[OperationContract]
bool Subscribe();
[OperationContract]
bool Unsubscribe();
}
What I want:
WPF1
[CallbackBehaviorAttribute(ConcurrencyMode = ConcurrencyMode.Multiple)]
public partial class MainWindow : Window, ITestCallBack1, IDisposable//,IDeviceCallBack
{
private InstanceContext context;
private DeviceClient deviceClient;
public MainWindow()
{
InitializeComponent();
context = new InstanceContext(this);
deviceClient = new DeviceServiceReference.DeviceClient(context);
}
public void Dispose()
{
deviceClient.Close();
}
public void Test1()
{
throw new NotImplementedException();
}
// Not Wanted
//public void Test2()
//{
// throw new NotImplementedException();
//}
}
WPF2
[CallbackBehaviorAttribute(ConcurrencyMode = ConcurrencyMode.Multiple)]
public partial class MainWindow : Window, ITestCallBack2, IDisposable //,IDeviceCallBack
{
private InstanceContext context;
private DeviceClient deviceClient;
public MainWindow()
{
InitializeComponent();
context = new InstanceContext(this);
deviceClient = new DeviceServiceReference.DeviceClient(context);
}
public void Dispose()
{
deviceClient.Close();
}
// Not Wanted
//public void Test1()
//{
// throw new NotImplementedException();
//}
public void Test2()
{
throw new NotImplementedException();
}
}
I am not completely clear on your requirement here but I will take a shot at helping anyway…
So, you can have only a single callback interface per service in WCF which means you will need two services. You can do some inheritance though so that you do not have to duplicate anything on your server. Following is an example that I hope explains how to do it…
Here is the configuration for the services:
Then on the client you need a reference to the service that you are interested in the callback for (so your WPF 1 would reference /TestService1 and WPF 2 /TestService2).
Notice that you can put all the logic that is common to your two services in the TestServiceBase class – it takes the callback interface just so that it can call it. In reality you may not need this – I do not know under what circumstances you are wishing to call back to the client