我的WCF - 配置在我的开发人员计算机上运行得很好。当我尝试将其发布到演示环境(另一台服务器)时,它会给我以下错误:
An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'log4net' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.
我的配置,在两种情况下都是相同的:
<system.serviceModel>
<services>
<service name="UI.WS.Services.MyService" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="wsHttpBinding"
contract="UI.WS.Services.IMyService"
bindingConfiguration="WsSecurityMode">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" />
<!-- Extension -->
<log4net />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WsSecurityMode">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<extensions>
<behaviorExtensions>
<!-- Extension -->
<add name="log4net" type="UI.WS.ErrorHandling.Log4NetBehaviorExtensionElement,UI,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
</system.serviceModel>
我已经检查了这个hint,这不是问题(如果是的话,它也不会在开发环境下运行)。
有什么建议吗?
答案 0 :(得分:1)
好吧,我尝试typeof(UI.WS.ErrorHandling.Log4NetBehaviorExtensionElement).AssemblyQualifiedName
给了我UI.WS.ErrorHandling.Log4NetBehaviorExtensionElement, UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
。这适用于两种环境。对我来说这是一个奇怪的问题 - 为什么第一个版本(没有空格)在我的开发人员机器上工作?在这两种环境中,应用程序池都在.Net 4.0.3下运行,因此这里没有区别。此外,我记得在某处隐约阅读时,由于WCF的错误,类型声明中的空格应该被遗弃,这似乎不是这里的情况。
无论哪种方式,现在都可以这样:
<add name="log4net" type="UI.WS.ErrorHandling.Log4NetBehaviorExtensionElement, UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />