Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are WCF services stateless by default?

I've got a simple WCF service that lets clients/consumer applications log in by providing a username and password. If both the username and password are correct, the WCF service provides the client with a GUID. The GUID and the username are then stored as a key/value pair within the WCF service. From here onwards, the client sends their GUID with every request as a means of identification.

Since I'm storing the key/value pair in a Dictionary/Hashmap, this approach would only work if the WCF service is stateful. Question is, are they stateful by default or is there something I have to do to make them behave in that manner?

like image 763
rafale Avatar asked May 18 '11 20:05

rafale


People also ask

Is WCF service stateless?

They are stateless by default and I would highly recommended keeping it that way if possible.

Is WCF stateless or stateful?

In this way, each request is served by a new service instance. It means a new service instance is created for each request and destroyed after the request is served. This make your WCF service stateless means you can't maintain states between WCF calls.


1 Answers

Per-call services are the Windows Communication Foundation default instantiation mode. So, by default, WCF services do not maintain state. As Marc stated, there are potential problems with saving state in WCF services. I strongly suggest heeding his advice.

This article describes various ways to handle instance management in WCF, including how to maintain state like you're asking for.

Chapter 4 of Juval Lowy's excellent Programming WCF Services (link) goes into much greater detail.

like image 130
Tad Donaghe Avatar answered Sep 28 '22 01:09

Tad Donaghe