Skip to content

What is the default for WCF if InstanceContextMode is not set explicit

If the attribute InstanceContextMode is not set explicit, the mode depends on the wcf settings. To be more specific, it depends on the "reliableSession and on the "security mode" properties in case of wsHttpBinding.

wsHttpBinding: "ReliableSession = false", and "SecurityMode = none" means it is PerCall.

image

wsHttpBinding:  "ReliableSession = false", and "SecurityMode=Message" means it is PerSession.

image

wsHttpBinding: "ReliableSession = true", and "SecurityMode=none" means it is PerSession.

image

basicHttpBinding: It is always PerCall.

image

 

If you set the attribute "PerSession" where the settings doesn't allow to use sessions(because of using basicHttpBinding, or because of not using security and relaiability on wsHttpBindng), a exception is thrown at startup.

It is best practice to set the expected InstanceContextMode explicit, then it is clear what wcf will do(either what you say, or fail at startup)

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

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

Documentation: http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontextmode.aspx

Trackbacks

Comments

Display comments as Linear | Threaded

Himanshu on :

what for wsHttpBinding: "ReliableSession = false", and "SecurityMode=Transport" means it is PerSession

corporate video production on :

Utilize the InstanceContextMode property to indicate when new service objects are made. Since the service question isn't specifically associated with the conveying channel, the lifetime of the administration objects is autonomous of the lifetime of the channel between a customer and the service application.

https://payforresearchpaper.com on :

I use the service as a web service one and all can call it (via WCF, ASMX client, Java, whatever), I don't have control over the customer then so they could brand my service hang when they don't near the client and I don't famine that.

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Markdown format allowed
Form options