LicenseAcquirer.AcquireLicenseAsync Method (Guid, ContentKeyType, Guid)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Starts the license acquisition process.

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Sub AcquireLicenseAsync ( _
    keyId As Guid, _
    keyType As ContentKeyType, _
    serviceId As Guid _
)
public void AcquireLicenseAsync(
    Guid keyId,
    ContentKeyType keyType,
    Guid serviceId
)

Parameters

  • keyId
    Type: System.Guid
    The key identifier of the file you are attempting to get the license for.
  • serviceId
    Type: System.Guid
    The service ID. This parameter is required only if you want to obtain a domain-bound license.

Exceptions

Exception Condition
InvalidOperationException

If this method is called when an existing license acquisition attempt is already in progress on that instance of the class.

InvalidOperationException

If this LicenseAcquirer was previously used for a MediaElement base license acquisition.

Examples

In offline scenarios, users download a content file before they play it. Because downloading a media file can take time and bandwidth, consider validating the user license before allowing the download, instead of validating when the user attempts playback. The following example shows how to do this.

The following application uses a key identifier and an authentication token to send a license acquisition request to the license server. The license server responds with a license and the URL from which to download the content.

// Called when the user is online and wants to download some protected content.
public void GetLicensePreDelivery(string customData,
                                     Guid keyId)
{
    Uri licenseServerUrl = new Uri("https://contoso.com/myLicenseServer.asmx");
    LicenseAcquirer acquirer = new LicenseAcquirer();
    acquirer.ChallengeCustomData = customData;

    // Set the License URI to proper License Server address.
    acquirer.LicenseServerUriOverride = licenseServerUrl;
    acquirer.AcquireLicenseCompleted += new EventHandler<AcquireLicenseCompletedEventArgs>(acquirer_Completed);
    acquirer.AcquireLicenseAsync(keyId, ContentKeyType.Aes128Bit, Guid.Empty);
}

The AcquireLicenseAsync call completes after starting the license acquisition but without waiting for the long content download operation to finish. When the license acquisition actually completes, the delegate that is configured on the AcquireLicenseCompleted event is called. In this example, that is the acquirer_Completed method, and it might look like in the following example.

public void acquirer_Completed(object sender, AcquireLicenseCompletedEventArgs e)
{
    if (e.Error != null)
    {
        // take appropriate action.  Might be retrying for instance.
    }
    else if (e.Cancelled)
    {
        // take appropriate action.  Might be nothing.
    }
    else
    {
        //
        //  We acquired the license successfully, go ahead and download
        //  the content.  Note the service decided to stash the content 
        //  url in the LicenseAcquirer response custom data.
        //
        string contentAcquisitionUrl = e.ResponseCustomData;
        DownloadContent(contentAcquisitionUrl);
    

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.