【问题标题】:Why does my WIF enabled WCF service throw exception when I try to host it?为什么我的 WIF 启用 WCF 服务在我尝试托管它时会引发异常?
【发布时间】:2011-03-10 18:07:13
【问题描述】:

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

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

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

我之前从未设置过使用 WIF 的 WCF 服务,但我已经成功设置网站使用 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> 

【问题讨论】:

    标签: wcf wif sts-securitytokenservice


    【解决方案1】:

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

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

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

    【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      我认为您需要添加适当的配置部分:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多