Sessionid为WCF中的每个请求获取更改 [英] Sessionid get change for each request in WCF

查看:62
本文介绍了Sessionid为WCF中的每个请求获取更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

  每当用户请求到达WCF时,我的sessionid都会更改.我正在为我的Silverlight应用程序使用WCF.在WCF中,我的属性如下所示:

    My sessionid get change every time when the user request come to WCF. Am using WCF for my silverlight application. In the WCF i have the attribute as below

[

ServiceContract (名称= typeof ( )))] 界面

ServiceContract(Name="DuplexService1", CallbackContract = typeof(IUCallbackContract))] for the Interface

and

[

OperationContract (IsOneWay = )]来进行方法清理.但是,无论何时从客户端发出请求,sessionid都会更改 在WCF中的继承类中.为什么会发生.我想为单个客户端维护单个SessionId和Channel.如何做到这一点

OperationContract(IsOneWay = true)] for the method decleration. But when ever an request is come from the client side the sessionid get changed in inherided class in WCF. Why it happen. i want to maintain the single SessionId and Channel for single client. How to achive this

推荐答案

您可以维护自己的会话,并将其添加到消息头中,如下所示:

You could maintain your own session and add it to the message header as follows:

Proxy proxy = new Proxy();
using (OperationContextScope scope = new OperationContextScope((IContextChannel)proxy))
{
  MessageHeader header = MessageHeader.CreateHeader("Session", "http://mydomain/session", Guid.NewGuid());
  OperationContext.Current.OutgoingMessageHeaders.Add(header);
  string data1 = channel1.GetData();
  Console.WriteLine(data1);
  proxy.Close();
}

干杯

Francois


这篇关于Sessionid为WCF中的每个请求获取更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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