3

WS2007FederationHttpBinding을 사용하는 WCF 서비스에서 생성 된 서비스 참조가있는 WinForms 응용 프로그램이 있습니다. 다음 이유가 작동하지 않는 이유를 이해할 수 없습니다.WCF 서비스 참조가있는 클라이언트에서 IssuedToken을 사용하는 방법

내 WinForms 앱이 BearerKey 형식 토큰을 처리하도록 설정된 Thinktecture.IdentityServer를 사용하는 WCF 서비스를 호출하고 있습니다. 나는 단순히 유효한 액세스 토큰을 획득하고,이 호출하게 내 클라이언트에서

:

<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> 

내가 시도 : 여기

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(); 
    } 

는 서비스 참조에 대한 윈폼 클라이언트의 app.config입니다 및 서비스 호출을 실행하십시오 (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, and confusing, config에 지정된 발급자가있는 것처럼 보입니다!

마지막으로,이 모든도 토큰을 적용하려면이 동일한 방법을 사용하여, 사용자 정의 ChannelFactory에를 사용하여 잘 작동하기 때문에 WCF 서비스 및 ID 서비스가 유효 알고

var channel = factory.CreateChannelWithIssuedToken(token);

하지만 내 요구 사항입니다 생성 된 ServiceReference를 사용합니다. :

답변

0

서비스 참조에서 생성 된 프록시를 사용할 수있는 유일한 방법은 자동으로 토큰을 요청하고 서비스 호출을하기 전에 작성한 프록시 인스턴스에서 적절한 ClientCredentials 속성을 설정하는 것입니다. WIF를 사용하는 경우

우리는 우리가 주위 I가 작업 프로젝트의 클라이언트에 캐시 계속 발급 된 토큰을 사용하고 있지만 우리는 채널 공장 당신이 설명하는 것처럼 CreateChannelWithIssuedToken를 사용해야합니다.

을 BTW,이다 .NET 4.0에서 실행하는 경우 다른 옵션이있을 수 있습니다.

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(); 
}