2012-08-23 31 views
1

我自己託管使用自定義BehaviorExtension的REST服務。當我的行爲擴展添加到ServiceBehaviors我得到以下錯誤:WCF配置錯誤 - 擴展名未註冊

"Invalid element in configuration. The extension name 'unityServiceBehavior' is not registered in the collection at 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> 

上任何想法?

編輯:我在某處讀到行爲擴展需要註冊的配置,以便它被加載。

有什麼特別的,我需要做的註冊擴展的配置?

謝謝。

+0

套管問題可能? rene

+0

我看到小寫的u。仍然收到錯誤。好眼睛rene!我將使用此更正編輯我的帖子。 –

回答

0

UnityServiceBehavior類需要從BehaviorExtensionElement派生。

我可以建議過你改變你的行爲的名稱如下:

​​

爲你提供了元素的名稱相同的類(甚至區分明智)也可能模糊焦點...

在你BehaviorExtensionElement得到你需要重寫CreateBehavior類()

+0

嗨克里斯,感謝您的意見。是的,我已經創建了一個繼承自BehaviorExtensionElement的類。另外,我同意命名。這只是我的帖子上的一個錯字。無論如何,通過在GAC中註冊行爲,我已經超過了上述錯誤消息。現在我得到一個新的但類似的錯誤。我懷疑它與我的64位機器有關。 –

0

本來我是收到以下錯誤:

"Invalid element in configuration. The extension name 'unityServiceBehavior' is not registered in the collection at system.serviceModel/extensions/behaviorExtensions."

我通過在dll(現在稱爲My.UnityWCF)中刪除行爲並將自定義行爲註冊到GAC中來解決此錯誤。但是,現在我得到一個新的但類似的錯誤。

The extension of type 'My.UnityWCF.UnityServiceBehavior, My.UnityWCF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ab794c43d4083d4c' is not registered in the extension collection 'behaviorExtensions'.

我使用WCF配置編輯器將行爲添加到behaviorExtensions集合。

<behaviorExtensions> 
    <add name="unityWCF" type="My.UnityWCF.UnityServiceBehavior, My.unityWCF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
</behaviorExtensions> 
1

要添加上面已經很好的答案:我將此錯誤添加到machine.config文件後遇到此錯誤。

我以後才注意到,雖然我的應用程序池的.NET版本與我修改machine.config文件的.NET版本不一樣,但遇到問題。 (v2.0 vs v4.0)。

將應用程序池設置爲正確的版本爲我解決了這個錯誤。

很明顯,但很容易錯過與IIS的無經驗的人(有時像我一樣)。