我自托管使用自定义 BehaviorExtension 的 REST 服务。当我将行为扩展添加到 ServiceBehaviors 时,我收到以下错误:
“配置中的元素无效。扩展名 'unityServiceBehavior' 未在 system.serviceModel/extensions/behaviorExtensions 的集合中注册。”
我的 App.Config 如下:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" name="My.Core.Services.PartyService">
<endpoint behaviorConfiguration="RESTBehavior" binding="webHttpBinding" name="PartyService" contract="My.Core.Services.IPartyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/parties" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
<!--Adding this behavior causes the error />-->
<UnityServiceBehavior />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RESTBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="UnityServiceBehavior" type="My.Core.Services.UnityServiceBehavior, My.Core.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> </configuration>
对此有任何想法吗?
编辑:我在某处读到,行为扩展需要在配置中注册才能加载。
我需要做一些特别的事情来使用配置注册扩展吗?
谢谢。