views:

708

answers:

1

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?

+3  A: 

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

marc_s
Yep, that was you. Thanks!
David Lively
+1 for helpful default wsHttpBinding info. Should the interface read `interface IYourService` instead of `IYourSession`? I was trying to link the two samples together :) Thanks!
Brandon Linton