Question How to update the GUI on the WCF Service side when a method is called from the Client

viswaroopan

New member
Joined
Oct 13, 2015
Messages
3
Programming Experience
5-10
Can someone help or share a simple code to show, how can we update the GUI on the .NET C# WCF Service side when the client calls the service method.

Looks like when the service is open using myServiceHost.Open() it creates its own thread and the GUI runs on its own thread. Now the service can't get to the GUI controls when the client application calls this method.

Thank you for your help in advance.
 
Your question doesn't seem to make sense. How would the service even know that the GUI exists? The service simply receives requests and sends data back. It's up to the GUI application to update itself based on the result of those requests.
 
Sorry I did not give you the full picture of the problem here. This WCF Service is not installed as a windows service. It has got a GUI and through which the WCF service is run within the application. Now the WCF Service is running in its own thread and the GUI is running in a main thread. So when a call comes from a client, you cannot access the GUI controls from that method. How do you display the data in that call on the GUI control?
 
When self-hosting service you use ServiceHost, this can be initialized with the singleton instance of your service, which will allow you to listen for event from that class.
When your service receives requests the service class methods can raise events and pass the data received, the GUI can then receive this data by its event handlers.
The GUI event handlers will be called in secondary thread context, to use GUI controls at least in Windows Forms environment you have to use Control.Invoke to pass execution to GUI thread.

A different approach may be using WCF message inspectors.
 
Back
Top Bottom