tags:

views:

11

answers:

1

Let's consider this chat service:(the entire application may be found here)

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IChatCallback))]
interface IChat
{
    [OperationContract(IsOneWay = false, IsInitiating = true, IsTerminating = false)]
    string[] Join(string name);

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = false)]
    void Say(string msg);

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = false)]
    void Whisper(string to, string msg);

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = true)]
    void Leave();
}

The Join method initiates a session and the Leave method ends it. Let's say i want to authenticate my users, create a service IAuth let's say with 2 methods Login and Logout. How should i initiate and terminate the session(because from what i've read this application requires a session) in this case, having different services? PS: i am new to wcf so any piece of advice helps. Thanks

+1  A: 

You don't need to initiate or terminate session (although technically it is possible) by yourself. WCF will do that for you. It will initiate sessions once Join will be called and will terminate session once Leave will be called.

Incognito
It will do because there is IsInitiating=true on Join and IsTerminating=true on Leave, but consider some other severice that allows user to make other stuff..i must also use IsInitiating=true on Login and IsTerminating=true on Logout?
jack
It depends from the service logic. Do you really want to allow to have several initiation points. I mean is it OK for you that and Login and Join will initiate a session. May be you need to review it ...
Incognito