简体   繁体   中英

Exit WCF service in IIS Express from code

Like what I say in the title, how can we exit that service (which starting together with the client application) when we turn off the client app? I try to call _serviceClient.CloseAsync() but the service still there in IIS Express. So do we have any way to do it?

UPDATE: My service is handle camera and stream the image to the client side. So if I don't exit the service, it will hold the camera until we turn it off from IIS manually. So I want to turn off two sides together.

I handled the release camera function in Close-action off the app. but sometime that unexpected, the app is crashed so that code isn't run.

Mostly this problem arises when the sender is not aware of the listener being terminated. For example in UDP streaming.

One solution is to have the listener send "heartbeat" messages to indicate it is still there and listening at a certain interval. If the heartbeat is not received any more, the server can conclude the client is not listening any more for whatever reason and free resources ( stop stream, release camera ... ).

Mind that UDP is not reliable, so single heartbeats may go missing. You'll have to see what exactly the perfect configuration of heartbeat-frequency and "missing beats"-tolerance will work for you and the network.

A common pattern for this is to implement a protocol, in which the client must send "acknowledge" - messages to the server to indicate received packages (since UDP packages of the stream could also need to be resent).

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