当我尝试托管它时,为什么我的WIF启用WCF服务抛出异常?

时间:2010-07-01 17:04:28

标签: wcf wif sts-securitytokenservice

按照此处的说明操作:http://msdn.microsoft.com/en-us/library/ee517277.aspx,我正在尝试设置WCF服务以使用WIF。

当我尝试实例化ServiceHost时,抛出以下异常:

  

无法加载为扩展名“federatedServiceHostConfiguration”注册的“Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement”类型。

我之前从未设置WCF服务以使用WIF,但我已成功设置网站以使用WIF。可能是什么导致了这个?

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> 

3 个答案:

答案 0 :(得分:3)

我得到了同样的错误。您需要将整行添加到配置文件中:

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

这是来自这个例子。但是,我实际使用的是Version = 3.5.0.0

答案 1 :(得分:1)

我很瘦,你需要添加适当的配置部分:

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

答案 2 :(得分:0)

您也可以通过其中一个启动例程中的代码处理此问题。

Microsoft.IdentityModel.Tokens.FederatedServiceCredentials.ConfigureServiceHost(wcfHost, FederatedAuthentication.ServiceConfiguration);
FederatedAuthentication.ServiceConfiguration.AudienceRestriction.AllowedAudienceUris.Add(endpoint.Address.Uri);
相关问题