I am trying to make a connection between two services. Service1 will send event notifications to service2.
I want to use callbacks, between these two services. service1 will send event to service2 and service2 will pass the event to a client.
Is it possible to use callbacks between two services?
I have already looked into the samples of wcf callbacks, but cant find anything between service to service communication.
Any help is appreaciated. see below the code of 1 of the services. my question: how is the code of the other service is going to look like with the callback in it?
Or is it in this case one of the services acting like a client? And how should that be looking like?
Service1 code:(Interface class)
public interface IMyEvents
{
[OperationContract(IsOneWay = true)]
void Event1();
}
[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IMyEvents))]
public interface SampleInterface
{
[OperationContract]
void DoSomethingAndFireEvent();
[OperationContract]
void SubscribeEvent();
}
This is the service class
public class SampleHandlerSimulator : SampleInterface
{
static Action m_Event1 = delegate { Console.WriteLine("Catch");};
public void SubscribeEvent()
{
IMyEvents subscriber = OperationContext.Current.GetCallbackChannel<IMyEvents>();
m_Event1 += subscriber.Event1;
}
public static void FireEvent()
{
m_Event1();
}
public void DoSomethingAndFireEvent()
{
CCStateHandlerSimulator.FireEvent();
}