user402186
user402186

Reputation: 489

Constructor called with every method call WCF HTTPS

I have a strange issue (or may be only strange for me)

I had a WCF WebSrvice hosted with wsHttpBinding. (HTTP)

All was good.

I switched to basicHttpBinding because i wanted to access it from PHP. I also made my service HTTPS so now its basicHttpBinding over HTTPS.

The service is working fine (almost as expected), and methods are working as expected too.

However I have noticed, in last configuration (wsHttpBinding, HTTP), when client used to call first method my service constructor used to call, and then for every other method it never called again. (which was good, as i was executing some code in constructor, that i wanted to run only once when client starts using the service)

But in the new configuration (basicHttpBinding, HTTPS), the constructor is called for every method executed.

Is this normal, or am I doing some thing wrong? If its normal, then first of all, what should i do for the code that i want to run once per session (client). And if you have time, why is it so, that over HTTP behavior is different, and over HTTPS it is different? (or is it because of the difference in bindings?)

Thanks.

Upvotes: 2

Views: 1756

Answers (1)

dlev
dlev

Reputation: 48596

The default InstanceContextMode for a WCF service is PerSession, and this is supported over HTTP by the binding you were using. However, HTTPS prevents this default sessioning behavior from occurring, and so you are seeing PerCall behavior (which will construct a new service object each time.) See this post about a way to correct this.

Upvotes: 4

Related Questions