3Dave
3Dave

Reputation: 29051

WCF binding -wsHttpBinding uses a session?

In a previous thread one of the respondents said that using wsHttpBinding used a session. Since I'm working in a clustered IIS environment, should I disable this? As far as I know, sessions don't work in a cluster.

If I need to disable this, how do I go about it?

Upvotes: 1

Views: 2995

Answers (1)

marc_s
marc_s

Reputation: 755128

That probably was me :-) By default, your service and the binding used will determine if a session comes into play or not.

If you don't do anything, and use wsHttpBinding, you'll have a session. If you want to avoid that, you should:

  • switch to another protocol/binding where appropriate
  • decorate your service contracts with a SessionMode attribute

If you want to stop a service from ever using a session, you can do so like this:

[ServiceContract(Namespace="....", SessionMode=SessionMode.NotAllowed)]
interface IYourSession
{
....
}

and you can decorate your service class with the appropriate instance context mode attributes:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
class YourService : IYourService
{
  ....
}

With this, you should be pretty much on the safe side and not get any sessions whatsoever.

Marc

Upvotes: 5

Related Questions