【问题标题】:Adding attribute to BehaviorExtensionElement将属性添加到 BehaviorExtensionElement
【发布时间】:2011-11-01 13:08:59
【问题描述】:

我正在为 WCF 添加一个自定义的 behaviorExtensionElement,并希望添加一个可以在读取配置的元素时读取的属性,例如

<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="myExtension"
             type="Bar.FooBarElement, Bar"/>
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <myExtension myAttribute="Foo" />

但是,我收到错误消息“无法识别的属性 'myAttribute'。请注意,属性名称区分大小写。”

我怎样才能避免这种情况?如何读取代码中的 myAttribute 值?

【问题讨论】:

标签: wcf configuration wcf-configuration servicebehavior


【解决方案1】:

事实证明这很简单,因为 BehaviorExtensionElement 是 ConfigurationElement 的子类,所以通常的配置规则适用。

[ConfigurationProperty("myAttribute")]
public string MyAttribute
{
  get { return (string)this["myAttribute"]; }
  set { this["myAttribute"] = value; }
}

【讨论】:

  • 是否可以将 BehavoiorExtensionElement 添加为服务接口中的属性,例如: [myExtension] bool UpdateObject(object myObject); ??非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-02
  • 1970-01-01
  • 1970-01-01
  • 2014-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多