Sundhas
Sundhas

Reputation: 605

Webservices are stateless?

Why do we say that web services are stateless?

Upvotes: 27

Views: 35890

Answers (5)

Jennifer Zouak
Jennifer Zouak

Reputation: 1348

The concept of a web serivce is to model a RPC (Remote Procedure Call) aka a Function. Thus you should not need to use session. In addition, the idea of being stateless comes from the need to scale out web servers into a server farm and thus enable higher capacity.

However, the choice of using state is dependant upon the technology and the developer. There is nothing to prevent you from creating an ASP.Net Web Service and setting "EnableSession=True" in the method definition.

This can be useful in some basic authentication scenarios, i.e. home-grown forms authentication or to provide automatic correlation for short-lived "workflow"'s. (However I strongly urge you consider more modern techniques will provide a higher level of security and performance).

Upvotes: 4

Pascal MARTIN
Pascal MARTIN

Reputation: 401032

Because web services are based on HTTP, which is a stateless protocol.

Quoting wikipedia :

A stateless server is a server that treats each request as an independent transaction that is unrelated to any previous request.

i.e. each request is independant from the previous one : even if we use some "tricks", like cookies for instance, to preserve some state between requests, this is not something defined by the protocol.

Upvotes: 18

Matt Stephenson
Matt Stephenson

Reputation: 8620

Because HTTP is stateless. After a client request is fulfilled by the server, no information is stored for use in future transactions.

Upvotes: 4

jldupont
jldupont

Reputation: 96746

Requests are independent from one another.

Upvotes: 2

brian
brian

Reputation: 1080

They don't persist any state between requests from the client. i.e. the service doesn't know, nor care, that a subsequent request came from client that has/hasn't made a previous request. Basically, its a 'give me this piece of info and forget about me' which puts the onus on the client to maintain any state.

Upvotes: 50

Related Questions