简体   繁体   中英

WCF, how to self-host callback?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM