Share via


Using CardSpace With wsHttpBinding

이 샘플에서는 웹 서비스에서 CardSpace를 사용하도록 wsHttpBinding을 구성하는 방법을 보여 줍니다.

참고

이 샘플의 설치 절차 및 빌드 지침은 이 항목의 끝부분에 나와 있습니다.

이 샘플에서는 ISecureCalculator 계약을 정의하여 CardSpace가 나타내는 개인 ID 클레임의 사용을 보여 줍니다. CalculatorService는 다음 샘플 코드에서 보여 주는 것처럼 ISecureCalculator라는 서비스 계약을 정의하고 구현합니다.

[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
public interface ISecureCalculator
{
    [OperationContract]
    double Add(double n1, double n2);
    [OperationContract]
    double Subtract(double n1, double n2);
    [OperationContract]
    double Multiply(double n1, double n2);
    [OperationContract]
    double Divide(double n1, double n2);
    [OperationContract]
    string GetIdentity();
}

서비스는 CardSpace에서 제공하는 SAML 토큰이 필요하도록 구성됩니다.

GetIdentity 작업의 서비스 구현에서는 PPID(Private-Personal-Identifier) 클레임을 추출하고 이를 응답으로 반환합니다. PrivatePersonalIdentifier는 토큰 발급자가 생성하는 기본 제공 개인 정보 기능이 있는 고유한 상수입니다. 서비스는 계정 조회 및 인증에 이 식별자와 그 밖의 정보(예: 발급자의 서명, 다른 클레임)를 함께 사용할 수 있습니다. PPID는 동일한 카드가 선택되었더라도 서비스별로 다릅니다.

const string ppidClaimType = 
"https://schemas.xmlsoap.org/ws/2005/05/identity/claims/ privatepersonalidentifier"; 
public string GetIdentity()
{
 string identity=String.Empty;

 AuthorizationContext ctx = OperationContext.Current.ServiceSecurityContext.AuthorizationContext;

 foreach (ClaimSet claimSet in ctx.ClaimSets)
 {
    foreach (Claim claim in claimSet.FindClaims(ppidClaimType, null))
    {
        identity += claim.Resource as string; 
    }
 }

    return identity;
}

다음 샘플 구성에서 보여 주는 것처럼, 서비스는 구성 파일(Web.config)에 정의된 단일 끝점을 노출하며, 여기서 요청자의 CardSpace가 필요합니다.

   <services>
      <service 
       name="Microsoft.ServiceModel.Samples.CalculatorService" 
       behaviorConfiguration="ServiceCredentials">
        <!-- This endpoint is exposed at the base address provided by host: https://localhost/servicemodelsamples/service.svc  -->
        <endpoint address=""
         binding="wsHttpBinding"
         bindingConfiguration="requireInfoCard"
         contract="Microsoft.ServiceModel.Samples.ISecureCalculator" >
          <identity>
            <certificateReference 
             findValue="545c3b8e97d99fd75c75eb52c6908320088b4f50" 
             x509FindType="FindByThumbprint" 
             storeLocation="LocalMachine" 
             storeName="My" />
          </identity>
        </endpoint>
        <!-- The mex endpoint is exposed at https://localhost/servicemodelsamples/service.svc/mex. -->
        <endpoint address="mex"
          binding="mexHttpBinding"
          contract="IMetadataExchange" />
      </service>
    </services>

    <bindings>
      <wsHttpBinding>
        <binding name="requireInfoCard">
          <security mode="Message">
            <message clientCredentialType="IssuedToken" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

또한 이 서비스는 서비스 인증서를 지정하도록 동작을 구성하는데, 이는 클라이언트에서 서비스를 인증하고 서비스에 보내는 메시지를 보호할 때 사용합니다.

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceCredentials">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceCredentials>
            <serviceCertificate
             findValue="545c3b8e97d99fd75c75eb52c6908320088b4f50"
             x509FindType="FindByThumbprint"
             storeLocation="LocalMachine"
             storeName="My" />
            <issuedTokenAuthentication allowUntrustedRsaIssuers="true" />
          </serviceCredentials>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

또한 클라이언트는 CardSpace에서 제공하는 SAML 토큰이 필요하도록 구성되어 서비스를 맨 처음 요청할 때 CardSpace 사용자 인터페이스가 시작됩니다. 사용자는 서비스에 제시할 적절한 정보 카드를 선택할 수 있습니다. 정보 카드를 선택하면 ID를 나타내는 SAML 토큰을 사용하여 요청이 보호됩니다. ISecureCalculator 계약의 GetIdentity 작업은 SAML 토큰에 제공된 PrivatePersonalIdentifer 클레임을 추출하여 이를 호출자에게 반환합니다.

클라이언트는 Service Metadata Utility Tool (Svcutil.exe)에서 생성한 형식화된 WCF 클라이언트 클래스를 사용하여 서비스와 통신합니다. 형식화된 WCF(Windows Communication Foundation) 클라이언트 클래스는 GeneratedProxy.cs 파일에 포함되어 있습니다.

클라이언트에 대한 구성은 Service Metadata Utility Tool (Svcutil.exe)를 사용하여 생성할 수도 있습니다. Service Metadata Utility Tool (Svcutil.exe)는 서비스에서 게시하는 메타데이터에 따라 클라이언트 끝점 구성을 만듭니다. 이 샘플에서는 서비스 구성부터 시작하여 수동으로 클라이언트 구성을 만듭니다.

다음 샘플 구성에서 보여 주는 것처럼, 클라이언트는 clientCredentialTypeIssuedToken으로 설정하고 CardSpace가 서비스를 인증할 수 있도록 certificateReference를 구성해야 합니다.

    <client>
      <endpoint
       address="https://localhost/ServiceModelSamples/service.svc/"
       bindingConfiguration="requireInfoCard" 
       binding="wsHttpBinding"
       contract="Microsoft.ServiceModel.Samples.ISecureCalculator"
       behaviorConfiguration="ClientCredentials">
        <identity>
          <certificateReference
           findValue="545c3b8e97d99fd75c75eb52c6908320088b4f50" 
           x509FindType="FindByThumbprint"
           storeLocation="CurrentUser" 
           storeName="TrustedPeople" />
        </identity>
      </endpoint>
    </client>

    <bindings>
      <wsHttpBinding>
        <binding name="requireInfoCard">
          <security mode="Message">
            <message clientCredentialType="IssuedToken" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

끝점에서 서비스 인증서를 제공하는 것 외에도 클라이언트는 신뢰하는 서비스의 인증서를 지정해야 합니다. 그러기 위해 클라이언트가 신뢰하는 인증서 저장소의 인증서를 참조하는 동작을 정의합니다.

    <behaviors>
      <endpointBehaviors>
        <behavior name="ClientCredentials" 
         includeExceptionDetailInFaults="true">
          <clientCredentials>
            <serviceCertificate>
              <defaultCertificate
               findValue="545c3b8e97d99fd75c75eb52c6908320088b4f50"
               x509FindType="FindByThumbprint"
               storeLocation="CurrentUser"
               storeName="TrustedPeople" />
              <!-- 
            Setting the certificateValidationMode to PeerOrChainTrust means that if the certificate 
            is in the user's Trusted People store, then it will be trusted without performing a
            validation of the certificate's issuer chain. This setting is used here for convenience so that the 
            sample can be run without having to have certificates issued by a certificate authority (CA).
            This setting is less secure than the default, ChainTrust. The security implications of this 
            setting should be carefully considered before using PeerOrChainTrust in production code. 
            -->
              <authentication
               revocationMode="NoCheck"
               certificateValidationMode="PeerOrChainTrust" />
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>

클라이언트를 실행하고 Enter 키를 누르면 클라이언트는 GetIdentity 작업을 호출하고 CardSpace 사용자 인터페이스가 시작됩니다.

  • CardSpace에서 이미 존재하는 카드를 선택하거나 새 카드를 만듭니다.
  • 보내기를 클릭하여 카드를 제출합니다.

해당 CardSpace의 클레임은 CardSpace의 SAML 토큰 serialization으로서 서비스에 보내집니다. 서비스 GetIdentity 작업은 SAML 토큰에서 추출된 클레임으로 응답합니다. 그런 다음 클라이언트는 서비스의 계산기 작업을 호출하며, 콘솔 창에 응답이 표시됩니다.

Identity - (Private Personal ID) =  LGGjXshcVQE1kFMnxccopDBGvYu6gVs2Aexx+4bMlbk=

Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Divide(22,7) = 3.14285714285714

Press <ENTER> to terminate client.

샘플을 설치, 빌드 및 실행하려면

  1. Windows Communication Foundation 샘플의 일회 설치 절차를 수행했는지 확인합니다.

  2. 단일 컴퓨터 또는 다중 컴퓨터 구성에서 샘플을 실행하려면 다음 지침을 사용합니다. 샘플 설치 디렉터리의 언어별 디렉터리에서 Setup.bat를 실행합니다.

    참고

    Setup.bat 배치 파일은 Windows SDK 명령 프롬프트에서 실행되도록 디자인되었습니다. MSSDK 환경 변수는 SDK가 설치되는 디렉터리를 가리켜야 합니다. 이 환경 변수는 Windows SDK 명령 프롬프트 내에서 자동으로 설정됩니다. Windows Vista의 경우 IIS 6.0 호환성 지원이 IIS 7.0에 설치되어 있는지 확인합니다.

  3. C# 또는 Visual Basic 버전의 솔루션을 빌드하려면 Windows Communication Foundation 샘플 빌드의 지침을 따릅니다.

  4. 샘플 실행을 마쳤으면 샘플 설치 디렉터리의 언어별 디렉터리에서 Cleanup.bat를 실행합니다.

단일 컴퓨터 구성에서 샘플을 실행하려면

  1. Simple\SampleResources\Fabrikam-Contoso.pfx 인증서를 LocalMachine/My (Personal) 인증서 저장소로 가져옵니다. 이 인증서의 암호는 xyz입니다.

    참고

    Fabrikam-Contoso.pfx 파일 대신 Fabrikam-Contoso-Public.cer 파일을 가져오지 마십시오.

  2. Simple 디렉터리의 언어별 디렉터리에서 Setup.bat를 실행합니다. 그러면 CurrentUser/TrustedPeople 인증서 저장소에 Fabrikam-Contoso-Public.cer 인증서가 설치되어 클라이언트에서 사용할 수 있게 됩니다. 또한 IIS 호스팅 웹 서비스에 이전 단계에서 설치한 Fabrikam 인증서의 개인 키를 읽을 수 있는 권한도 부여됩니다.

    참고

    Windows Vista에서 인증서를 수동으로 가져온 다음 Setup.bat를 실행합니다. 이렇게 하지 않으면 "키 세트가 없습니다."라는 오류가 발생할 수 있습니다.

    참고

    CardSpace 샘플 실행을 마쳤으면 Cleanup.bat를 실행하여 인증서를 제거해야 합니다. 다른 CardSpace 샘플에서도 동일한 인증서를 사용합니다. Setup.bat 배치 파일은 Windows SDK 명령 프롬프트에서 실행되도록 디자인되었습니다. MSSDK 환경 변수는 SDK가 설치되는 디렉터리를 가리켜야 합니다. 이 환경 변수는 Windows SDK 명령 프롬프트 내에서 자동으로 설정됩니다.

  3. Simple 폴더의 언어별 폴더에 있는 샘플 Visual Studio 솔루션 파일 CardSpace.sln을 빌드합니다.

  4. 서비스가 실행 중인지 확인하려면 웹 브라우저에서 https://localhost/servicemodelsamples/service.svc라는 주소를 엽니다. 서비스의 요약이 표시됩니다.

  5. Simple\<CS,VB>\client\bin에서 client.exe를 시작합니다.

  6. 클라이언트와 서비스가 통신할 수 없는 경우 문제 해결 팁을 참조하십시오.

다중 컴퓨터 구성에서 샘플을 실행하려면

  1. 웹 서비스를 호스팅하는 서버의 경우

    1. 서버에 샘플 소스 디렉터리가 없는 경우 TechnologySamples\Basic\Binding\WS\CardSpace\Simple 디렉터리를 서버에 복사합니다.

    2. Simple\SampleResources\Fabrikam-Contoso.pfx 인증서를 LocalMachine/My (Personal) 인증서 저장소로 가져옵니다. 이 인증서의 암호는 xyz입니다.

      참고

      Fabrikam-Contoso.pfx 파일 대신 Fabrikam-Contoso-Public.cer 파일을 가져오지 마십시오.

    3. Simple 디렉터리의 언어별 디렉터리에서 Setup.bat를 실행합니다.

      참고

      Setup.bat는 클라이언트에 필요한 인증서를 CurrentUser/TrustedPeople에 설치하며 로고 이미지를 ServiceModelSamples 가상 디렉터리에 복사합니다. 이 작업을 수행하지 않으려면 Setup.bat를 실행하지 말고 서비스의 인증서를 설치합니다.

    4. Simple\<CS,VB>\service\service.csproj 프로젝트를 빌드합니다.

    5. 서비스가 실행 중인지 확인하려면 웹 브라우저에서 https://localhost/servicemodelsamples/service.svc라는 주소를 엽니다. 서비스의 요약이 표시됩니다.

      참고

      서버에서 샘플 실행을 마쳤으면 Simple 폴더의 언어별 디렉터리에서 Cleanup.bat를 실행합니다.

  2. 클라이언트를 호스팅하는 컴퓨터의 경우

    1. 컴퓨터에 샘플 소스 디렉터리가 없는 경우 TechnologySamples\Basic\Binding\WS\CardSpace\Simple 디렉터리를 컴퓨터에 복사합니다.
    2. Simple 디렉터리의 언어별 디렉터리에서 Setup.bat를 실행합니다. Fabrikam-Contoso.pfx에 포함된 서비스 인증서는 설치할 필요가 없습니다.
    3. Simple\<CS,VB>\client\client.csproj 프로젝트를 빌드합니다.
    4. client\bin\client.exe.config 파일에서 <endpoint address=" https://localhost/ServiceModelSamples/service.svc" .../>의 주소를 웹 서비스의 새 주소와 일치하도록 변경합니다.
  3. client\bin\client.exe를 실행합니다.

    참고

    샘플 실행을 마쳤으면 Cleanup.bat를 실행합니다.

  4. 클라이언트와 서비스가 통신할 수 없는 경우 문제 해결 팁을 참조하십시오.

샘플 실행 후 정리를 수행하려면

  1. 샘플 설치 디렉터리의 언어별 디렉터리에서 Cleanup.bat를 실행합니다.

Send comments about this topic to Microsoft.
© 2007 Microsoft Corporation. All rights reserved.