Search code examples
c#wcfservicelimitip

How To Limit a WCF Service Application, So That Only Unique Clients Can Access


i have a wcf service in c# (like the calculatorservice from msdn examples), and i was wondering is it possilble to limit it to serve only 1 client per IP?

i want the possibility of a few IPs to be connected at once (at least 5-6 active sessions), and that works for now, but i don't want more than 1 connection per unique IP (or unique computer)


Solution

  • i made some progress. when the client invokes the service for the first time, in the constructor i save his ip address and his current operation context.

    then, if someone from the same ip connects, i abort the previous channel that that ip address used (newest connection has the priority):

    operationContext.Channel.Abort();
    

    i tested it, and it appears to free up the session so others can use it, but i am not sure -- is this the best solution?