1

カスタム 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>

これに関するアイデアはありますか?

編集:動作拡張をロードするには、構成に登録する必要があることをどこかで読みました。

拡張機能を構成に登録するために何か特別なことをする必要がありますか?

ありがとう。

4

3 に答える 3

1

上記のすでに優れた回答を追加するには:これをmachine.configファイルに追加した後、このエラーが発生しました。

トラブルシューティング中に、アプリケーション プールの .NET バージョンが、machine.config ファイルを適用した .NET バージョンと同じではないことに後で気付きました。(v2.0 対 v4.0)。

アプリケーションプールを正しいバージョンに設定すると、このエラーが修正されました。

非常に明白ですが、IIS を使用した経験のない人 (私のように) は見逃しがちです。

于 2013-11-13T14:19:58.840 に答える
0

UnityServiceBehavior クラスは BehaviorExtensionElement から派生する必要があります。

次のように、行動の名前を変更することも提案できますか。

    <serviceBehaviors>   
            <behavior name="MyServiceTypeBehaviors" >   
                <serviceMetadata httpGetEnabled="true" />   

                <!--Adding this behavior causes the error />-->   
                <unityServiceBehavior />   
            </behavior>   
        </serviceBehaviors> 


       <behaviorExtensions> 
           <add name="unityServiceBehavior" type="My.Core.Services.UnityServiceBehavior,     My.Core.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
       </behaviorExtensions> 

要素にクラスと同じ名前を付けたので(大文字と小文字を区別しても)、問題が曇る可能性もあります...

BehaviorExtensionElement から派生するクラスでは、CreateBehavior() をオーバーライドする必要があります

于 2012-08-24T08:42:38.407 に答える
0

もともと、次のエラーが発生していました。

「構成の無効な要素です。拡張機能名 'unityServiceBehavior' は、system.serviceModel/extensions/behaviorExtensions のコレクションに登録されていません。」

動作を dll (現在は My.UnityWCF と呼ばれる) にストライプアウトし、カスタム動作を GAC に登録することで、このエラーを回避しました。ただし、今では新しいが同様のエラーが発生しています。

タイプ 'My.UnityWCF.UnityServiceBehavior, My.UnityWCF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ab794c43d4083d4c' の拡張は、拡張コレクション 'behaviorExtensions' に登録されていません。

WCF 構成エディターを使用して、behaviorExtensions コレクションに動作を追加しました。

<behaviorExtensions>
    <add name="unityWCF" type="My.UnityWCF.UnityServiceBehavior, My.unityWCF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
</behaviorExtensions> 
于 2012-08-28T13:42:59.010 に答える