1

按照此处的说明: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> 
4

3 回答 3

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

于 2010-10-12T21:54:13.800 回答
1

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

  <configSections>
    <section name="microsoft.identityModel" type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </configSections>
于 2010-07-07T04:09:00.950 回答
0

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

Microsoft.IdentityModel.Tokens.FederatedServiceCredentials.ConfigureServiceHost(wcfHost, FederatedAuthentication.ServiceConfiguration);
FederatedAuthentication.ServiceConfiguration.AudienceRestriction.AllowedAudienceUris.Add(endpoint.Address.Uri);
于 2010-07-07T16:53:18.280 回答