I have a WCF Service which is hosted by a Windows Service. It can also run as a console program when a command argument is present. It has one interface that employs MSMQIntegrationBinding, and another that binds to HTTP for service utility methods. This works well. I have a web application (written for IE 11) that lets the user monitor the service, and perform the utility methods. There are many Console.WriteLines in the code that obviously don't display if the code is running as a service.
My boss has now requested that he be able to view the service in action in a console, like it were running as a console app. I would like to add a new virtual console window to my web app that would just display new Console.WriteLines as they occur on the server. I was thinking I could write a function in my wcf service that would accept the message as a string, do a Console.WriteLine, and then push out the message to any listening clients like my web app console window. I'm thinking of using javascript on the client.
I've read about using Websockets with netHttpBinding for a WCF service and that's the approach I would like to take. However, the examples I see seem to be bi-directional, like chat windows (http://www.codeproject.com/Articles/619343/Using-WebSocket-in-NET-4-5-Part-3) that just echo back a message to the client. I want one way server-to-client messaging. Can somebody help? Here's my latest code try:
IWMLogger.VB
<ServiceContract(CallbackContract:=GetType(IWMLogger_MessageCallback))>
Public Interface IWMLogger_ClientListener
<OperationContract(IsOneWay:=True)>
Function ListenForServerMessages() As Task
End Interface
<ServiceContract>
Interface IWMLogger_MessageCallback
<OperationContract(IsOneWay:=True)>
Function SendMessageToClient(ByVal msg As String) As Task
End Interface
WMLogger.VB
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single)> _
Public Class WMLogger_Service
Implements IWMLogger_Service, IWMLogger_Service_MSMQ, IWMLogger_ClientListener
Public Async Function ListenForServerMessages() As Task Implements IWMLogger_ClientListener.ListenForServerMessages
Dim callback = OperationContext.Current.GetCallbackChannel(Of IWMLogger_MessageCallback)()
If DirectCast(callback, IChannel).State = CommunicationState.Opened Then
'Not sure what to do here
'Await callback.SendMessageToClient(
End If
End Function
End Class