tags:

views:

128

answers:

3

Following the instructions here: http://msdn.microsoft.com/en-us/library/ee517277.aspx, I am trying to set up a WCF service to use WIF.

When I try to instantiate the ServiceHost, the following exception is thrown:

The type 'Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement' registered for extension 'federatedServiceHostConfiguration' could not be loaded.

I have never set up WCF service to use WIF before, but I have successfully set up web sites to use WIF. What could be causing this?

Module Module1    
    Sub Main()  
        Dim sh As ServiceModel.ServiceHost  
        ''#Exception thrown on following line
        sh = New ServiceModel.ServiceHost(GetType(testService))  
        Microsoft.IdentityModel.Tokens.FederatedServiceCredentials.ConfigureServiceHost(sh)
        sh.Open()
        Console.WriteLine("Service running")
        Console.ReadLine()
       sh.Abort()
    End Sub
End Module

 

<?xml version="1.0" encoding="utf-8" ?>  
<configuration><system.serviceModel>  
    <behaviors>  
        <serviceBehaviors>  
          <behavior name="ClaimsBehavior" >  
            <federatedServiceHostConfiguration/>  
          </behavior>  
        </serviceBehaviors>  
    </behaviors>  
    <services>  
        <service behaviorConfiguration="ClaimsBehavior"  name="WCFConsoleService.testService">  
            <endpoint address="net.tcp://localhost/testservice" binding="netTcpBinding"  
                bindingConfiguration="" contract="WCFConsoleService.iTestService" />  
        </service>  
    </services>  
    <extensions>  
        <behaviorExtensions>  
            <add name="federatedServiceHostConfiguration"
                 type="Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement" >  
        </behaviorExtensions>  
    </extensions>  
</system.serviceModel>  
</configuration> 
A: 

I thin you need to add the appropriate config section:

  <configSections>
    <section name="microsoft.identityModel" type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </configSections>
Eugenio Pace
A: 

You can also handle this via code in one of your startup routines.

Microsoft.IdentityModel.Tokens.FederatedServiceCredentials.ConfigureServiceHost(wcfHost, FederatedAuthentication.ServiceConfiguration);
FederatedAuthentication.ServiceConfiguration.AudienceRestriction.AllowedAudienceUris.Add(endpoint.Address.Uri);
Flesrouy
A: 

I was getting the same error. You need to add this entire line to the config file:

<add name="federatedServiceHostConfiguration" type="Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement, Microsoft.IdentityModel, Version=0.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

This is from the example. However, I actually used Version=3.5.0.0

Jim