在 WCF 中管理状态的最可扩展的方法是什么。
我只需要一个变量来指示会话,我将在 MSSQL 中管理与会话相关的信息。我不需要知道会话何时结束。每天一次,我将清除所有旧会话。
看来 SessionID 就是那个变量。
对于规模,我使用 Per Call,因为 ctor 是空的。我认为我不需要每次会话。
在我简单的 EightBall 测试中,我得到了一个代表会话的 SessionID。但我只是在一个盒子上测试。
让我担心的是,我看到一些文档需要将 ReliableSessionBindingElement 设置为 On 并且默认情况下它是 Off 。
在以下配置中,SessionID 是否会成为会话的可靠指标?
<system.serviceModel>
<services>
<service name="MajicEightBallServiceLib.MagicEightBallService"
behaviorConfiguration="EightBallServiceMEXBehavior" >
<endpoint address=""
binding="wsHttpBinding"
contract="MajicEightBallServiceLib.IEightBall" />
<endpoint address="mex"
binding ="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/MagicEightBallService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="EightBallServiceMEXBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
[ServiceBehavior (InstanceContextMode=InstanceContextMode.PerCall)]
public class MagicEightBallService : IEightBall
{
public MagicEightBallService()
{
Console.WriteLine("Eightball awaits your question ...");
}
public string ObtainAnswerToQuestion(string userQuestion)
{
return "maybe " + OperationContext.Current.SessionId.ToString();
}
public sDoc GetSdoc(int sID)
{
List<sDocProp> props = new List<sDocProp>();
sDocProp prop1 = new sDocProp { ID = 1, Name = "Prop1", ArrivalStatus = ArrivalStatus.OnTime };
props.Add(prop1);
sDocPropStringSV prop2 = new sDocPropStringSV { ID = 1, Name = "Prop1", ArrivalStatus = ArrivalStatus.OnTime, Value = "StrValue1" };
props.Add(prop2);
sDoc sDoc = new sDoc { sID = sID, sParID = 1, Props = props, SessionID = OperationContext.Current.SessionId.ToString() };
return sDoc;
}