我正在开发一个连接到声明软件 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>