AppFabric Service Bus SDK e .NET 4.0

Portando alcune demo per DevCon 2010 alla versione 4.0 del .NET Framework ho riscontrato questo problema…

L’errore si verifica utilizzato l’SDK 1.0 per AppFabric Service Bus con .NET 4.0.

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

(D:\\Applications\\EstatesManagement\\Current\\DevLeap.EstatesManagement.UI.WPF.SmartClient
\\bin\\Debug\\DevLeap.EstatesManagement.UI.WPF.SmartClient.vshost.exe.Config line 101)"}

Sulla stessa macchina una applicazione .NET 3.5 con Visual Studio 2008 gira benissimo con il service bus, mentre la stessa applicazione con Visual Studio 2010 non gira.

Il problema (e la soluzione) è molto semplice: installando l’SDK per il Service Bus vengono aggiunti nel machine.config nuovi binding e nuovi behavior per supportare la comunicazione WCF con il service bus. L’SDK però aggiorna solo il machine.config della versione 3.5.

Se usate la versione 4.0 occorre prendere dalla versione 2.0 (ricordo che la 3.0 e la 3.5 sono aggiunte alle 2.0 come runtime quindi il machine.config della 2.0 è il nostro riferimento) behaviorExtension, bindingElementExtension e bindingExtension, nonchè i metadati aggiunti dall’installazione dell’sdk.

Il “problema” ovviamente si presenta anche durante il deploy, ma in questo caso non è ovviamente un problema in quanto è normale dover aggiungere elementi esterni alla configurazione di una applicazione (web.config o app.config) quando si usano l’sdk esterni al framework stesso.

Vi riporto per completezza l’elenco delle aggiunte da fare alla sezione <system.serviceModel>

<system.serviceModel>
    <extensions>
        <behaviorExtensions>
            <add name="connectionStatusBehavior" type="Microsoft.ServiceBus.Configuration.ConnectionStatusElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </behaviorExtensions>
        <bindingElementExtensions>
            <add name="tcpRelayTransport" type="Microsoft.ServiceBus.Configuration.TcpRelayTransportElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="httpRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpRelayTransportElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="httpsRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpsRelayTransportElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="onewayRelayTransport" type="Microsoft.ServiceBus.Configuration.RelayedOnewayTransportElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </bindingElementExtensions>
        <bindingExtensions>
            <add name="basicHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.BasicHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="webHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WebHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="ws2007HttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WS2007HttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="netOnewayRelayBinding" type="Microsoft.ServiceBus.Configuration.NetOnewayRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add name="netEventRelayBinding" type="Microsoft.ServiceBus.Configuration.NetEventRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </bindingExtensions>
    </extensions>
    <client>
        <endpoint address="" binding="netTcpRelayBinding" contract="IMetadataExchange" name="sb"/>
        <metadata>
            <policyImporters>
                <extension type="Microsoft.ServiceBus.Description.TcpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <extension type="Microsoft.ServiceBus.Description.HttpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <extension type="Microsoft.ServiceBus.Description.OnewayRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            </policyImporters>
            <wsdlImporters>
                <extension type="Microsoft.ServiceBus.Description.StandardRelayBindingImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <extension type="Microsoft.ServiceBus.Description.TcpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <extension type="Microsoft.ServiceBus.Description.HttpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <extension type="Microsoft.ServiceBus.Description.OnewayRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            </wsdlImporters>
        </metadata>
    </client>

hope useful