gpt4 book ai didi

wcf - 向 BehaviorExtensionElement 添加属性

转载 作者:行者123 更新时间:2023-12-04 22:15:35 25 4
gpt4 key购买 nike

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

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

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

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

最佳答案

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

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

关于wcf - 向 BehaviorExtensionElement 添加属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7154614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com