从 Silverlight 访问声明感知 WCF



我正在开发一个连接到声明软件WCF服务的Silverlight 4应用程序。我使用以下代码检索 WCF 中的声明令牌以执行授权。

IClaimsPrincipal principal = ( IClaimsPrincipal )Thread.CurrentPrincipal;   
IClaimsIdentity identity = ( IClaimsIdentity )principal.Identity;
return string.Format( "You entered: {0} and you are {1}", value, identity.Name );

当我在 WCF 中使用 wsHttpBinding 并使用控制台应用程序试用它时,它工作正常。但是由于 Silverlight 只支持 basicHttp 和 customeBinding,所以我不能使用 wsHttp、ws2007Http 或任何其他绑定。在这种情况下,我没有从Silverlight获得WCF中的IClaimIdentity令牌。

有什么方法可以使用任何 Silverlight 支持的绑定,并且仍然在我的 WCF 中获取 ClaimIdentity。是否有任何教程/帮助文本,我可以在其中阅读更多有关此内容的信息。

我的 WCF 设置是:

<system.serviceModel>
    <services>
      <service name="ClainAwareWCF.Service" behaviorConfiguration="ClainAwareWCF.ServiceBehavior">
        <endpoint address="" binding="basicHttpBinding" contract="ClainAwareWCF.IService" bindingConfiguration="basicbind">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="basicbind">
          <security mode="TransportCredentialOnly"></security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ClainAwareWCF.ServiceBehavior" > 
          <federatedServiceHostConfiguration/>
          <serviceMetadata  httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>      
      <behaviorExtensions>
        <add name="federatedServiceHostConfiguration" type="Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </behaviorExtensions>
    </extensions>
  </system.serviceModel>

由于绑定问题以及 SL 的客户端身份验证感知安全性(Windows/Forms/WIF/等),尝试直接从客户端调用此内容永远不会发生,但一种方法是使用 RIA 服务域身份验证服务通过 WCF RIA 调用终结点从服务器端进行身份验证和调用服务。 用户的安全上下文代理到客户端,您可以直接通过线路传输数据。

这可能会让你朝着正确的方向前进:

http://archive.msdn.microsoft.com/RiaServices/Release/ProjectReleases.aspx?ReleaseId=5617

Silverlight 不支持开箱即用的基于声明的授权和 WS-Trust。Microsoft打算把它放到Silverlight 5中,但不幸的是忘记了这样做。

但是,在

身份训练工具包中有一个非常优雅且可用的WIF IdentityModel内容的"Silverlight"版本。

该解决方案包括一个基本身份验证服务(将 WIF 身份验证令牌转换为声明服务器端)和一个 Silverlight 客户端库"SL.IdentityModel"包含构建块,例如 ClaimsPrincipal 的 Silverlight 版本。

在此处获取身份培训工具包。查找示例 Silverlight 实现。

最新更新