0

I have a WCF service lib which run by a self-host [Winform] and a client [Winform], and im using NetTcpBinding.

i want the client to call a method from WCF service to Pop up a MessageBox on Self-host Winform.
the point: i want to send an image to the server side, and it should appears in a new form, but i can't communicate between WCF service library and its Self-Host Form.

please can you help with an example that shows me how would i show a messageBox on Self-host winform when a client call a method from WCF service lib.

Murhaf Sousli
  • 12,622
  • 20
  • 119
  • 185

2 Answers2

0

You could create your service as a singleton and pass in the Form in its constructor. Then pass this service object into the ServiceBase.

Then when you get a function call you will have reference to the Form and can manipulate it in that fashion. Be aware of threading restriction on working with Form applications.

Kevin Green
  • 1,137
  • 11
  • 21
  • I'm new to WCF, can you post me a simple example! – Murhaf Sousli May 09 '12 at 14:53
  • @kevinGreen Adding user user interface specific things to Service is against the SOA principles. Your service should not really care about the way presentation logic handles things. – Nilesh Gule May 10 '12 at 08:31
  • The question is very specific about how to communicate between the form and the service. Although this may not be best practice it answers the question. If you want true separation from the service and the GUI then the proper suggestion would be to include some events in the service that the GUI could bind to, then when the server receives an image from the client, it would fire an event. This event would then be captured by the GUI, which would pop open a new form. – Kevin Green May 16 '12 at 18:47
0

You can return a success or failure message from the service call which sends the image to the server side. Assuming that you were successful in sending the message to server, you can open a new form and populate the message box or whatever user interface control you wish o display to the user. As I mentioned in the comment, the service colud be multitenanted and you should not mix user interface relatd code in service layer.

Nilesh Gule
  • 1,511
  • 12
  • 13