title: Authentication against ADFS with WCF hosted on Windows service
body: <p>I have a wcf service that queries ADFS for SAML token. This is a common snippet from web to query ADFS and get back the SAML token.
  However it always ends up breaking at the line  <strong>return channel.Issue(rst); . Error is ID3082: The request scope is not valid or is unsupported.</strong>
  At least at an high level  i am not able to figure out whether the error is at the ADFS server end or with the way WCF service is configured or with code. Please help.</p>
  <pre><code>public SecurityToken GetSamlToken()
  {
      using (var factory = new WSTrustChannelFactory(
          new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
          new EndpointAddress(new Uri(&quot;https://serv/adfs/services/trust/13/usernamemixed&quot;))))
      {
          factory.Credentials.UserName.UserName = &quot;username&quot;;
          factory.Credentials.UserName.Password = &quot;password&quot;;
          factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
          factory.TrustVersion = TrustVersion.WSTrust13;                
          WSTrustChannel channel = null;                
          try
          {
              string KeyType;
              var rst = new RequestSecurityToken
              {
                  RequestType = WSTrust13Constants.RequestTypes.Issue,
                  AppliesTo = new EndpointAddress(&quot;net.tcp://localhost:xxxx/Service1/mex&quot;),                         
                  KeyType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.KeyTypes.Bearer,                                        
              };
  
              channel = (WSTrustChannel)factory.CreateChannel();
  
              return channel.Issue(rst);
          }
          finally
          {
              if (channel != null)
              {
                  channel.Abort();
              }
              factory.Abort();
          }
      }
  }
  </code></pre>