CAlling callbacks from outside service handler
-
OK, so I'm slowly making progress with WCF. I have a question on callbacks and where they can be called from. I've found this awesome article which, almost exactly, addresses what I'm trying to achieve. The hosting application has the following block of code:
using (ServiceHost host = new ServiceHost(typeof(BeerService)))
{
host.Open();Console.WriteLine("Service is ready for requests. Press any key to close service."); Console.WriteLine(); Console.Read(); Console.WriteLine("Closing service...");
}
Inside
BeerService
is where the magic happens. I'd like to trigger some of that magic from inside the server side application, the code block above, but how do I do that? I don't have access to an instance ofBeerService
, all I have is access tohost
which is an instance ofServiceHost
, notBeerService
. Essentially, this is what I'd like to be able to do, but can't:using (ServiceHost host = new ServiceHost(typeof(BeerService)))
{
host.Open();Console.WriteLine("Service is ready for requests. Press any key to close service."); Console.WriteLine(); int c; do { c = Console.Read(); if (c == 'b') // Here is the line that I'd like to be able to call but can't because MakeBeerRun() is a member of BeerService and I don't have access to an instance of it host.MakeBeerRun("The Party Owner", 12); } while (c == 'b'); Console.WriteLine("Closing service...");
}