I have a need to do some real-time rpoerting on the functionality of a WCF service. The service is self-hosted in a windows app, and my requirement is to report "live" to the host app when certain methods are called by the client.
My initial thought on the task was to publish a "NotifyNow" event in the service code, and subscribe to the event in my calling app, but this doesn't seem to be possible. Within my service code (implementation, not the interface) I have tried adding the following
public delegate void MessageEventHandler(string message);
public event MessageEventHandler outputMessage;
void SendMessage(string message)
{
if (null != outputMessage)
{
outputMessage(message);
}
}
and call the SendMessage method whenever I need to notify the host app of some action. (This is based on what I remember of this kind of inter-form communication in a winforms app, and my memory may have let me down here...)
When I try to hook up the event handler in my host, though, I can't seem to figure out how to attach to the events... My hosting code is (in a nutshell)
service = new ServiceHost(typeof(MyService));
service.outputMessage += new MyService.MessageEventHandler(frm2_outputMessage);
// the above line does not work!
service.Open();
(wrapped in a try/catch).
Can anyone help, either by telling me how to get this approach to work or by pointing me at a better way.
TIA