3

У меня есть приложение WinForms с ссылкой на службу, сгенерированное из службы WCF, которая использует WS2007FederationHttpBinding. Я не понимаю, почему следующее не работает.Как использовать IssuedToken в клиенте с ссылкой службы WCF

Приложение My WinForms вызывает службу WCF, использующую Thinktecture.IdentityServer, настроенную для обработки токенов типа 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."

Эта ошибка л 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(); 
}