【问题标题】:Attributes in service class in Windows Workflow Foundation servicesWindows Workflow Foundation 服务中的服务类中的属性
【发布时间】:2016-03-15 22:53:00
【问题描述】:

我已经在我的 WCF 服务中加入了一些安全功能,在我的服务类中放置了一些实现 IServiceBehavior 的自定义属性。例如:

[AuthenticationBehavior()]
public class BRService1 : ServiceBase, IBRService1

在哪里

public class AuthenticationBehavior : Attribute, IServiceBehavior
{
...
}

但是我需要对一些 WWF 服务做同样的事情,虽然我没有明确的服务类,我可以在其中添加属性。

您知道我可以在工作流服务中做同样事情的方法吗?

提前致谢。

【问题讨论】:

    标签: c# wcf workflow-foundation-4


    【解决方案1】:

    最后,经过大量的研究和测试,我在这篇文章中找到了答案:https://social.msdn.microsoft.com/Forums/vstudio/en-US/a9b45eaf-c8e2-444c-819d-e448868e68bb/using-workflow-extensions-contextgetextension-in-iishosted-workflows?forum=wfprerelease

    总结:

    1. 为继承自 BehaviorExtensionElement 的服务行为类创建一个包装类:

      public class AuthenticationElement : BehaviorExtensionElement
      {
          public override Type BehaviorType
          {
              get { return typeof(AuthenticationBehavior); }
          }
      
          protected override object CreateBehavior()
          {
              return new AuthenticationBehavior();
          }
      }
      
    2. 在公开工作流的服务配置文件中,在部分添加:

    2.1 之前创建的 BehaviorExtensionElement 的扩展:

    <extensions>
      <behaviorExtensions>
        <add name="authenticationBehaviorExt"
             type="Security.AuthenticationElement, Security"/>
      </behaviorExtensions>
    </extensions>
    

    2.2 服务行为:

    <behavior name="authenticationBehavior">
      <serviceMetadata httpGetEnabled="True" />
      <authenticationBehaviorExt />
    </behavior>
    

    2.3 将 serviceBehavior 添加到工作流服务定义中

    <service name="WFService" behaviorConfiguration="authenticationBehavior">
    <endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttp_Workflow" contract="IWFService" />
    </service>
    
    1. 享受吧。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多