3

我有一个WinForms应用程序,它具有从使用WS2007FederationHttpBinding的WCF服务生成的服务引用。我不明白为什么以下不起作用。如何在客户端使用带有WCF服务的IssuedToken

我的WinForms应用程序正在调用使用Thinktecture.IdentityServer WCF服务,建立处理BearerKey型令牌。

从我的客户,我只是获取有效的访问令牌,使这个电话:

private static void CallServiceReference(SecurityToken token) 
    { 
     ServiceReference1.ClaimsServiceContractClient svcRef = new ServiceReference1.ClaimsServiceContractClient(); 

     svcRef.ChannelFactory.Credentials.SupportInteractive = false; 
     svcRef.ChannelFactory.CreateChannelWithIssuedToken(token); 
     var claims = svcRef.GetClaims(); 
    } 

下面是服务引用的WinForms客户端的app.config:

<system.serviceModel> 
     <bindings> 
       <ws2007FederationHttpBinding> 
         <binding name="WS2007FederationHttpBinding_ClaimsServiceContract"> 
           <security mode="TransportWithMessageCredential"> 
             <message establishSecurityContext="false" issuedKeyType="BearerKey"> 
               <issuer address="https://identity.MyCo.com/issue/wsfed" binding="ws2007HttpBinding" 
                 bindingConfiguration="https://identity.MyCo.com/issue/wstrust/mixed/username" /> 
               <issuerMetadata address="https://identity.MyCo.com/issue/wstrust/mex" /> 
               <tokenRequestParameters> 
                 <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"> 
                   <trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType> 
                   <trust:CanonicalizationAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/10/xml-exc-c14n#</trust:CanonicalizationAlgorithm> 
                   <trust:EncryptionAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptionAlgorithm> 
                 </trust:SecondaryParameters> 
               </tokenRequestParameters> 
             </message> 
           </security> 
         </binding> 
       </ws2007FederationHttpBinding> 
       <ws2007HttpBinding> 
         <binding name="https://identity.MyCo.com/issue/wstrust/mixed/username"> 
           <security mode="TransportWithMessageCredential"> 
             <transport clientCredentialType="None" /> 
             <message clientCredentialType="IssuedToken" establishSecurityContext="false" /> 
           </security> 
         </binding> 
       </ws2007HttpBinding> 
     </bindings> 
     <client> 
       <endpoint address="https://roadie/WebTest/service.svc" binding="ws2007FederationHttpBinding" 
         bindingConfiguration="WS2007FederationHttpBinding_ClaimsServiceContract" 
         contract="ServiceReference1.ClaimsServiceContract" name="WS2007FederationHttpBinding_ClaimsServiceContract" /> 
     </client> 
    </system.serviceModel> 

当我尝试并执行服务调用(svcRef.GetClaims())我得到这个错误:

"The address of the security token issuer is not specified. An explicit issuer address must be specified in the binding for target ' https://identity.MyCo.com/issue/wsfed ' or the local issuer address must be configured in the credentials."

这个错误是l ame和混淆,看起来如何在配置中指定发行者!

最后,我所知道的WCF服务和身份服务是有效的,因为这一切都使用自定义的ChannelFactory正常工作,也使用此完全相同的方法来应用令牌:

var channel = factory.CreateChannelWithIssuedToken(token);

但我的要求是使用生成的ServiceReference。 :(

回答

0

我认为你可以使用从服务引用生成的代理的唯一方法是,如果你配置客户端自动请求令牌,并设置您作出服务调用之前创建的代理实例的适当ClientCredentials财产。

我们使用的是我们保持周围缓存中的一个项目,我的工作在客户端上发出的令牌,但我们必须使用通道工厂CreateChannelWithIssuedToken就像你描述。

顺便说一句,这是使用WIF时在.NET 4.0中,也许还有其他的选择,如果运行在.NET 4.5上

2

你应该使用这样创建的频道:

private static void CallServiceReference(SecurityToken token) 
{ 
    ServiceReference1.ClaimsServiceContractClient svcRef = 
     new ServiceReference1.ClaimsServiceContractClient(); 

    svcRef.ChannelFactory.Credentials.SupportInteractive = false; 
    var svcChannel = svcRef.ChannelFactory.CreateChannelWithIssuedToken(token); 
    var claims = svcChannel.GetClaims(); 
} 
相关问题