我有以下场景:
我有运行工作流事件的工作流应用程序对象。在工作流事件逻辑中,我调用了一个 WCF 服务,其中的服务操作也作为一组事件生成。
问题是:在这种情况下,我如何传递凭据并模拟其他用户,因为它经常这样做:
MyServiceClient client = new MyServiceClient();
client.ClientCredentials.Windows.ClientCredential.Domain = domain;
client.ClientCredentials.Windows.ClientCredential.UserName = username;
client.ClientCredentials.Windows.ClientCredential.Password = password;
我试图模拟运行工作流应用程序对象的代码块,但在那种情况下,我收到某种异常,提示“无法加载文件或程序集......访问被拒绝”。据我了解,此异常的原因是工作流应用程序正在尝试调用原始登录用户下的程序集。
有什么帮助吗?
最佳答案
使用调用进程凭据的 Windows 身份验证是最受支持的身份验证方法,但在 WF CodePlex 站点 (https://wf.codeplex.com/releases/view/48114) 上的 WF Security Pack CTP 1 中有处理用户名/密码身份验证的事件。请参阅 TokenFlowScope
和 GetUserNameSecurityToken
。本文详细介绍:http://msdn.microsoft.com/en-us/magazine/gg598919.aspx .我还没有尝试过,如果可能的话,我会尽量避免。
对于您的第二个问题,要使在 WorkflowApplication 下运行的工作流模拟,还需要做更多的工作。来自同一篇文章:
The security context of a calling thread isn’t copied to the workflow thread, so even if the workflow client is impersonating, the WF thread—which is executing the activities—won’t be impersonating. The security context of the caller can be flown to the WF thread using a custom Synchronization context that would forward the call on the same incoming Async thread, similar to the Synchronization context used by the WorkflowInvoker
public class MySyncContext : SynchronizationContext
{
public override void Post(SendOrPostCallback d, object state)
{
d(state);
}
}
关于wcf - 如何模拟在 WorkflowApplication 中执行的 WCF 客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7951671/