是WCF服务在默认情况下无状态? [英] Are WCF services stateless by default?

查看:166
本文介绍了是WCF服务在默认情况下无状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的WCF服务,可以让客户端/消费类应用提供了一个用户名和密码登录。如果两个用户名和密码都正确,WCF服务向客户端提供一个GUID。 GUID和用户名,然后保存为WCF服务中的一个键/值对。从这里开始,客户端发送的GUID与作为一种识别手段的每个请求。

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.

由于我存储在一个词典/ HashMap中的键/值对,这如果WCF服务是有状态的做法只会工作。问题是,他们是否为默认的状态或者是有什么我需要做的,使他们以这种方式表现?

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?

推荐答案

每-call服务是Windows Communication Foundation的默认实例化模式。因此,在默认情况下,WCF服务不维护状态。正如马克指​​出,有与WCF服务节能状态的潜在问题。我强烈建议听取他的意见。

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.

这的文章,介绍了各种方式来处理实例管理在WCF中,包括如何保持状态,就像你问的。

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

的Juval洛伊出色的第4章编程WCF服务(链接)进入更多的细节。

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

这篇关于是WCF服务在默认情况下无状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆