wcf - 如何模拟在 WorkflowApplication 中执行的 WCF 客户端?

标签 wcf workflow

我有以下场景:

我有运行工作流事件的工作流应用程序对象。在工作流事件逻辑中,我调用了一个 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 中有处理用户名/密码身份验证的事件。请参阅 TokenFlowScopeGetUserNameSecurityToken。本文详细介绍: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/

相关文章:

email - 在 CrafterCMS 中,设置工作流程还需要什么?

c# - WCF 工作流服务的输入参数在什么时候被实例化/设置?

workflow - 作风建议

wpf - 如何确保客户端保持连接到 WPV MVVM 应用程序中的 WCF 服务?

c# - WCF 双工回调,如何向所有客户端发送消息?

WCF 反序列化 - 反序列化程序不知道映射到此名称的任何类型

wcf - 保护 REST API/Web 服务的最佳实践

c# - 使用 Workflow 的 ASP.net 页面导航

hadoop - Oozie工作流程和协调员

c# - WCF 反序列化中的 XmlException : "Name cannot begin with ' <'" - in automatic property backing fields