Authentication 如何设置WorkflowService身份验证?

Authentication 如何设置WorkflowService身份验证?,authentication,workflow-foundation-4,wcf-security,Authentication,Workflow Foundation 4,Wcf Security,我只需要确保我的WF服务。找不到有关此的任何资源。怎么做 已尝试: class Program { static void Main(string[] args) { using (WorkflowServiceHost host = new WorkflowServiceHost(new Workflow1(), new Uri("http://localhost/Test"))) { host.Credentials.U

我只需要确保我的WF服务。找不到有关此的任何资源。怎么做

已尝试:

class Program
{
    static void Main(string[] args)
    {
        using (WorkflowServiceHost host = new WorkflowServiceHost(new Workflow1(), new Uri("http://localhost/Test")))
        {
            host.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = System.ServiceModel.Security.UserNamePasswordValidationMode.Custom;
            host.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new Test();

            host.Open();
            Console.Write("ready");
            Console.ReadLine();
        }
    }
}
public class Test : UserNamePasswordValidator
{
    public Test()
    {
        Console.Write("hit");
    }

    public override void Validate(string userName, string password)
    {
        Console.Write("never hit");
    }
}
和一个配置

<bindings>
  <wsHttpBinding>
    <binding>
      <security mode="Message">
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
      <!--<serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="myAssembly.Test, myAssembly" />
      </serviceCredentials>-->
    </behavior>
  </serviceBehaviors>

  • 无法创建固定名称终结点,因为它们是动态创建的
更新-我尝试了下面的配置并成功了,但我想要一种更精细的方法来设置每个服务使用的绑定

<protocolMapping>
  <add scheme="http" binding="wsHttpBinding"/>
</protocolMapping>

就消息传递部分而言,这只是WCF,因此您可以使用WCF执行的任何操作都应该在这里工作


也就是说,对于工作流,除了第一个请求,您通常需要对所有请求进行更细粒度的控制。例如,所有员工都可以启动en费用报告,但只有启动特定费用报告的员工才能向其中添加费用并提交。您可以使用进行此类安全检查。

我们有一集Workflow TV应该会有所帮助

有点粗俗,但很管用。重写WorkflowServiceHost以获取未知的协定名称并为每个协定添加服务终结点

    const string DEFAULT_WORKFLOW_SERVICE_BINDING_NAME = "WorkflowDefaultBinding";

    static void Main(string[] args)
    {            
        MyWorkflowServiceHost host = new MyWorkflowServiceHost(new CountingWorkflow2(), new Uri(hostBaseAddress));
        foreach (var contractName in host.ImplementedContractsNames)
        {
            // now I'm able to choose which binding to use depending on a condition
            var binding = new WSHttpBinding(DEFAULT_WORKFLOW_SERVICE_BINDING_NAME);

            host.AddServiceEndpoint(contractName, binding, string.Empty);
        }
    }
和MyWorkflowServiceHost

    public class MyWorkflowServiceHost : WorkflowServiceHost
    {
        public MyWorkflowServiceHost(Activity activity, params Uri[] baseAddresses)
            : base(activity, baseAddresses)
        {

        }

        private IDictionary<string, System.ServiceModel.Description.ContractDescription> _implementedContracts;
        public IEnumerable<string> ImplementedContractsNames
        {
            get
            {
                foreach (var contract in _implementedContracts)
                    yield return contract.Key;
            }
        }

        protected override System.ServiceModel.Description.ServiceDescription CreateDescription(out System.Collections.Generic.IDictionary<string, System.ServiceModel.Description.ContractDescription> implementedContracts)
        {
            System.ServiceModel.Description.ServiceDescription description = base.CreateDescription(out implementedContracts);

            _implementedContracts = implementedContracts;

            return description;
        }
    }
公共类MyWorkflowServiceHost:WorkflowServiceHost
{
公共MyWorkflowServiceHost(活动活动,参数Uri[]基本地址)
:基本(活动、基本地址)
{
}
私人词典执行合同;
公共IEnumerable实现的合同名称
{
得到
{
foreach(已实施合同中的var合同)
收益回报合同。关键;
}
}
受保护的覆盖System.ServiceModel.Description.ServiceDescription CreateDescription(out System.Collections.Generic.IDictionary implementedContracts)
{
System.ServiceModel.Description.ServiceDescription Description=base.CreateDescription(未执行的合同);
_已执行合同=已执行合同;
返回说明;
}
}
添加一个未命名的WSHttpBinding和下面关于服务模型的部分也应该可以工作,但对于默认配置来说

<protocolMapping>
  <add scheme="http" binding="wsHttpBinding"/>
</protocolMapping>


我在示例的web.config部分尝试了WCF配置,但没有成功。我在WCF中的做法是在配置文件上创建与服务同名的端点,并设置其绑定(和安全性)。但我不能这样做,因为是用户命名了工作流服务。我认为我所需要的就是指定某个服务将使用什么绑定-如何做?如果您希望所有工作流服务都使用相同的设置,可以创建一个未命名的绑定。所有服务都会将其作为默认值。您还可以使用WorkflowServiceHost配置绑定/端点。是的,我创建了一个未命名的绑定,并将默认协议映射设置为wshttpbinding,如问题所述。我正在尝试使用WorkflowServiceHost配置绑定/端点。唯一的问题是:怎么做?很好的资源,我怎么会错过呢?希望这个问题能帮助其他没有找到这个链接的人。视频很好,但正如你所说,它是关于架构、设计思想,而不是实现。(我的问题标题经过编辑,可能传递了我想了解其内部内容的想法,这将非常好,但还没有=])