WCF实现Session信息
来源:互联网 发布:c erp系统源码下载 编辑:程序博客网 时间:2024/06/11 15:45
新建两个类
public class ContextHeader : IClientMessageInspector{ public static Dictionary<string, Users> ListUsers = new Dictionary<string, Users>(); public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { } ~ContextHeader() { } public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel) { //这里是客户端调用方法时候会调用 每次调用方法都会调用 MessageHeader clientHeader = MessageHeader.CreateHeader("headerName", string.Empty, Guid.NewGuid().ToString()); request.Headers.Add(clientHeader); return null; }}
public class CallContextAttribute : Attribute, IEndpointBehavior, IOperationBehavior { ContextHeader ch = new ContextHeader(); public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime) { clientRuntime.ClientMessageInspectors.Add(ch); } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher) { } public void Validate(ServiceEndpoint endpoint) { } public void AddBindingParameters(OperationDescription operationDescription, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation) { clientOperation.Parent.ClientMessageInspectors.Add(ch); } public void ApplyDispatchBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.DispatchOperation dispatchOperation) { } public void Validate(OperationDescription operationDescription) { } }
然后你的Contract上就可以写
[ServiceContract] [CallContext] public interface SayHelloContract { [CallContext] [OperationContract] string SayHi(string HelloName); }
- WCF实现Session信息
- 利用WCF共享ASP.NET session实现WCF服务端验证
- WCF后续之旅(9):通过WCF的双向通信实现Session管理
- [原创]WCF后续之旅(9): 通过WCF双向通信实现Session管理[Part II]
- [原创]WCF后续之旅(9):通过WCF的双向通信实现Session管理[Part I]
- 使用WCF实现服务器向客户端的信息推送
- WCF中使用Session
- WCF 和 Session
- [原创]WCF后续之旅(6): 通过WCF Extension实现Context信息的传递
- WCF后续之旅(6): 通过WCF Extension实现Context信息的传递
- WCF常见问题(1) -- WebService/WCF Session Cookie
- WCF笔记(7)会话(Session)
- freamwork2实现单点登录,跨系统获取session信息
- WCF及log配置信息
- 化零为整WCF(11) - 会话状态(Session)
- WCF 及 Silverlight 中使用 Session
- 化零为整WCF(11) - 会话状态(Session)
- WCF中的Session和Instancing Management
- 一些学习java的一些技巧!
- 一个Tomcat支持不同的域名访问各自不同程序的配置方法实践
- 英文拼写纠错
- js 实现 map
- Linux下IPTABLES防火墙的设定
- WCF实现Session信息
- 数据库基本知识
- android漏洞收集3-短信程序smsreceiverservice服务暴露
- java开发webservice
- zxing文档版
- cocos2d-x v3.0代码差异
- Android NDK开发(2)----- JNI多线程
- 《Single Image Haze Removal Using Dark Channel Prior》一文中图像去雾算法的原理、实现、效果及其他。
- 我的博客