enzom83
enzom83

Reputation: 8310

How to uniquely identify a connection?

I created a sessionful service using NetTcpBinding: each client begins a session with the service, so I need to identify each session in some way. Obviously when a session ends, its identifier should also change, so that the application can understand that the client probably has changed.

I do not know if WCF or, in general, .NET provides a way to uniquely identify the various active sessions based on the requirements that I just described.

Alternatively I thought about the following idea:

public class ConnectionIdentifier {
    public UInt16 ConnectionNumber {get; set;}
    public Uint64 ConnectionTime {get; set;}
}

So, when a new session is established, I assign a session number (ie. ConnectionNumber) to it and the the time when the session was initiated (ie. ConnectionTime = DateTime.Now.Ticks). However, in this case, how can I identify the end of a session to release the corresponding number?

Moreover, are there alternative ways to uniquely identify a session?

Upvotes: 0

Views: 351

Answers (1)

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65411

WCF has built in functionality for this. The way to do it is to mark your service contract as "Per Session", you then get an instance of your service for each client/session.

See: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

Upvotes: 1

Related Questions