简体   繁体   中英

Allow only a single client at a time

I'm on the WCF coding now, and the question is quite standard:

I need my WCF server to manage a hardware device, so I critically need only 1 client allowed at a time. I did try some solutions found at the site, but neither

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
                 ConcurrencyMode = ConcurrencyMode.Multiple)]

nor the addition of

<behavior name="Throttled">
     <serviceThrottling maxConcurrentCalls="1"
     maxConcurrentSessions="1"
     maxConcurrentInstances="1" />
</behavior>

doesn't block me from running a 2nd application and ruining the server.

Should I learn more about client authentication or there is a magic line I can add to solve this part?

As I mentioned before, all those actions are not sufficient. Looks like the key is to maintain a WCF session mode - so, I added [ServiceContract (SessionMode = SessionMode.Required)] with wsHttpBinding instead of basicHttpBinding (which is not allowed to maintain a session). Now it works.

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