我有 WCF 服务,我正在尝试对其进行单元测试。该服务唯一的依赖是调用 OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name 以了解使用该服务的 Windows 用户(Windows 身份验证)我只想模拟这个。 有人有简单的方法吗?
最佳答案
根据您的服务配置方式,Thread.CurrentPrincipal 可能包含代表已连接客户端的委托(delegate)人。因此,您可以从中获取名称,而不是依赖于 OperationContext。
关于c# - WCF 服务中的模拟 OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23336801/