Using Activation Service.
Sample written in C#
Sample written in Visual Basic .NET

This sample doesn’t contain Manco.Licensing DLL itself in it, so don’t forget to download main archive from the 'Download - Manco .NET Licensing System' page.

The Activation Web Service is the separate part of Manco .NET Licensing System. It is designed to perform 4 main functions:

  1. Online product activation. Product activation is a technology is used by a number of licensing schemes available today. Manco .NET Licensing System allows you using product activation to bind license to a single computer so that the same license can’t be used on another PC. This operation can be performed manually using License Manager or automatically using Activation Web Service.
  2. Online Activation Key validation. You can configure your application to connect with Activation Web Service to check if the licensing information (license file or Unlock Key) and Activation Key are still valid and stop execution if they aren’t. So if you remove Activation Key or information about purchase from the database your application will not work (in case of money back, for example).
  3. Create licensing information (including license files and unlock keys) in automated mode. Activation Web Service can communicate with e-Commerce systems (like RegNow and ShareIt!) and create licensing information on demand by request from those systems. All necessary information about client and sale can be filled in at this time as well.
  4. To be data source for License Manager. License Manager can use Activation Web Service as data source instead of database.

In this article we describe how the Activation Web Service can be used for online product activation.

The Activation Web Service uses licensing schema that is similar to the Windows XP licensing. When you install Windows XP you enter the License Key that is printed on the sticker. When installation is finished you follow the process of Windows activation. During this process you obtain Activation Key from the Microsoft Activation Service. After that this particular copy of the Windows can work on one PC only.

Licensing scenario with Activation Web Service can be used when you’d like to bind licensed software to particular PC. This scenario limits using of your software with one PC per one License Key/License File bought from you. This schema works as following:

  1. While Unlock Key and Activation Key have not been entered and evaluation time has not been expired application works in the evaluation mode.
  2. If evaluation time is expired then application stop functioning.
  3. When customer buys a license you send licensing information (Unlock Key or license file).
  4. Customer applies licensing information and asks your application for activation. Application sends request to the Activation Web Service. It validates licensing information and generates Activation Key. Depends on the type of request Activation Key will be copied to the application and/or send to the customer by e-Mail.
  5. If both general licensing information (license file or Unlock Key) and Activation Key are valid application becomes fully functional.

We suppose that you have read section "Quick Start using ‘Unlock Key’ licensing schema" already. So we will describe only things are specific for the “Unlock Key with Activation” licensing schema.

Activation Web Service can automatically send e-Mail with Activation Key to user. If you’d like to use this functionality you should configure activation letter for product that uses activation schema.

Firstly we should create e-Mail configuration for Activation Letter. Select “e-Mail Configuration” tab in the License Manager. Click "Add new e-mail" toolbar button. New e-Mail configuration will be added. Rename it (“My Product activation e-Mail” for example). Most fields on the e-Mail configuration view are good known for most people are using e-Mails in their practice.

Activation e-Mail configuration

Following fields are required:

  1. From – your e-Mail address.
  2. Subject.
  3. SMTP Server – URL or IP address of the SMTP server will be used to send e-Mail.
  4. If your SMTP server requires authentication then you should check “Use SMTP Authentication” checkbox and fill “User” and “Password” fields.
  5. XSLT File Path – path to the XSLT file that will be used to creates e-Mail body. This path should be given relative to the file system of the server where Activation Web Service is installed in. See Appendix A for structure of XML data passed to the XSLT for transformation.

When all necessary fields will be filled in click "Save all" toolbar button to save changes made.

Now select “Product” tab and select version node. In the “Activation Letter” combo box select e-Mail configuration you have created:

Version info with Activation Letter specified

The “Unlock Key with Activation” license type can be defined as following:

Unlock Key with Activation license type
  1. Is Evaluation – indicates that license works as evaluation till Activation and Unlock Key will be entered.
  2. Expiration Days – sets number of day till evaluation license expire.
  3. Unlock Key – indicates that unlock key for this product issued by License Manager should be entered to get product fully functional.
  4. Activation Key – indicates that activation key created using PC system info and unlock key (ether in automatic or manual mode) should be entered to get product fully functional.
  5. Write Key To File – indicates that important license information (unlock and activation keys) should be stored in the license protected storage to reuse in future.

Then you should create evaluation license file using this license type. Evaluation license file shouldn’t contain any Unlock or Activation Key (correspondent fields must be empty). Correspondent evaluation sale record could look like the following:

Evaluation license

Pay attention that both: Unlock and Activation Keys are empty. Create license file and add it to your project.

Now you should prepare your product to use Activation Web Service.

Firstly add web reference to your project that will refer to the Activation Web Service:

  1. Right click your project in the Visual Studio Solution Explorer.
  2. Select “Add Web Reference” in the context menu.
  3. In the “Add Web Reference” dialog fill in “URL” field so it point to the Activation Web Service (something like http://yourhost/ActivationService/ActivationService.asmx).
  4. Click “Go” button. Wait till information about activation service will be obtained.
  5. Change Web reference name and click “Add Reference” button.
Add web reference

Add evaluation window to your project. It could looks like the following:

License Activation Form

Add “OnClick” event handler for the “Activate” button. This handler should set Unlock Key to the license object, obtain product ID and send it to the activation server.

[C#] 
private void cmdActivateAndFill_Click(object sender, EventArgs e)
{
	// If "Unlock Key" has been entered
	if (txtUnlockKey.Text.Trim() != string.Empty)
	{
		// Pass "Unlock Key" to the license object
		m_oLicense.UnlockKey = txtUnlockKey.Text.Trim();

		// Get instance of the Activation Service
		ActivationWebService.ActivationService loActivationService = 
			new ActivationWebService.ActivationService();
		try
		{
			// Get product ID from the license and try to activate it
			// Ask activation service to send copy of the key 
			// to the customer's e-Mail
			string lsActivationKey = 
				loActivationService.ActivateProductGetKey(
				m_oLicense.ProductID, 
				true);
			if (lsActivationKey != null)
			{
				// In case when product succesfully activated 
				// user will recieve e-Mail with activation code.
				txtActivationKey.Text = lsActivationKey;
				MessageBox.Show("Activation Key has been succesfully"
					+ " generated and passed to the text box."
					+ " Click OK to continue.");
			}
		}
		catch (Exception exc)
		{
			MessageBox.Show("Exception during activation:\n" 
				+ exc.ToString());
		}
	}
	else
	{
		MessageBox.Show("Enter Unlock Key to be able activate product");
	}
}
[Visual Basic .NET] 
Private Sub cmdActivateAndFill_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdActivateAndFill.Click
	' If "Unlock Key" has been entered
	If txtUnlockKey.Text.Trim() <> String.Empty Then
		' Pass "Unlock Key" to the license object
		m_oLicense.UnlockKey = txtUnlockKey.Text.Trim()

		' Get instance of the Activation Service
		Dim loActivationService As ActivationWebService.ActivationService = _
		New ActivationWebService.ActivationService()
		Try
			' Get product ID from the license and try to activate it
			' Ask activation service to send copy of the key to 
			' the(customer) 's e-Mail
			Dim lsActivationKey As String = _
			loActivationService.ActivateProductGetKey( _
			m_oLicense.ProductID, _
			True)

			If Not lsActivationKey Is Nothing Then
				' In case when product succesfully activated user 
				' will recieve e-Mail with activation code.
				txtActivationKey.Text = lsActivationKey
				MessageBox.Show("Activation Key has been succesfully " _
				& " generated and passed to the correspondent text box." _
				& " Click OK to continue.")
			End If
		Catch exc As Exception
			MessageBox.Show("Exception during activation:" _
			& vbCrLf _
			& exc.ToString())
		End Try
	Else
		MessageBox.Show("Enter Unlock Key to be able activate product")
	End If
End Sub

The evaluation window also should provide properties to get Unlock Key entered by user and Activation Key obtained from the Activation Web Service.

Next, the program needs to check to see the status of the license. If it is evaluation, or not valid, evaluation window needs to be shown that allows the user to input an Unlock Key and activate application. It looks like the best place for this code is “OnLoad” event handler:

[C#]
private void MainForm_Load(object sender, EventArgs e)
{
	// Check if the current license is evaluation license or not valid
	if (license.IsEvaluation || !license.IsValid)
	{
		// This is evaluation or not valid license, 
		// so we should show evaluation dialog 
		// This is evaluation license, so 
		// we should show license dialog 
		LicenseForm loForm = new LicenseForm(license);
		if (loForm.ShowDialog() == DialogResult.OK
			&& loForm.UnlockKey.Trim() != string.Empty
			&& loForm.ActivationKey.Trim() != string.Empty)
		{
			// License information have been entered.
			// Pass it to the license object for the
			// following validation.
			license.UnlockKey = loForm.UnlockKey;
			license.ActivationKey = loForm.ActivationKey;
		}
		else if (license.IsExpired)
		{
			// The evaluation license has been expired and 
			// no license information have been entered, 
			// so we should close application.
			Application.Exit();
		}
	}

	// Now you can use license object to validate license. 
	// License will be valid if it is evaluation license,
	// or entered valid Unlock and Activation keys.
	if (license.IsValid)
	{
		// Initialize application
		// Make some GUI elements available only when
		// Unlock Key and Activation Key have been entered
		// (license is valid and is not evaluation one).
		tsmiAvailableWhenActivated.Enabled = !license.IsEvaluation;
		txtAvailableWhenActivated.Enabled = !license.IsEvaluation;
		openToolStripButton.Enabled = !license.IsEvaluation;
		saveToolStripButton.Enabled = !license.IsEvaluation;
	}
	else
	{
		// It is not an evaluation license and valid Unlock Key 
		// and Activation Key have not been entered.
		MessageBox.Show("License Not Valid\nIllegal validator: " 
			+ license.InvalidValidator.ToString(), 
			"Sample Application", 
			MessageBoxButtons.OK, 
			MessageBoxIcon.Stop);
		Application.Exit();
	}
}
[Visual Basic .NET] 
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
	' Check if the current license is evaluation license or not valid
	If license.IsEvaluation Or Not license.IsValid Then
		' This is evaluation or not valid license, so 
		' we should show license dialog 
		Dim loForm As LicenseForm = New LicenseForm(license)
		If loForm.ShowDialog() = DialogResult.OK _
		 And loForm.UnlockKey.Trim() <> String.Empty _
		 And loForm.ActivationKey.Trim() <> String.Empty Then
			' License information have been entered.
			' Pass it to the license object for the
			' following validation.
			license.UnlockKey = loForm.UnlockKey
			license.ActivationKey = loForm.ActivationKey
		ElseIf license.IsExpired Then
			' The evaluation license has been expired and 
			' no license information have been entered, 
			' so we should close application.
			Application.Exit()
		End If
	End If

	' Now you can use license object to validate license. 
	' License will be valid if it is evaluation license,
	' or entered valid Unlock and Activation keys.
	If license.IsValid Then
		' Initialize application
		' Make some GUI elements available only when
		' Unlock Key and Activation Key have been entered
		' (license is valid and is not evaluation one).
		tsmiAvailableWhenActivated.Enabled = Not license.IsEvaluation
		txtAvailableWhenActivated.Enabled = Not license.IsEvaluation
		openToolStripButton.Enabled = Not license.IsEvaluation
		saveToolStripButton.Enabled = Not license.IsEvaluation
	Else
		' It is not an evaluation license and valid Unlock Key 
		' and Activation Key have not been entered.
		MessageBox.Show("License Not Valid" _
		+ vbCrLf _
		+ "Invalid Validator: " _
		+ license.InvalidValidator.ToString(), _
		"Sample Application", _
		MessageBoxButtons.OK, _
		MessageBoxIcon.Stop)
		Application.Exit()
	End If
End Sub

Now you application is ready to run. First time you start it you will see evaluation window with fields to enter Unlock and Activation keys and button for product activation. If you simple close this window your application will continue execution in the evaluation mode. You can check this mode using “IsEvaluation” property of the license object. You can enable or disable some functionality or GUI controls based on this status. To get your application fully functional you have to create “Unlock Key” and then activate it.

Click License Manager - Add new sale toolbar button. You will see “Add new sale” window. Enter necessary customer information. Actually it is enough enter customer name and e-Mail, but we would recommend at least First and Last name too. Activation Web Service can send activation e-Mail to customer. If you’d like use this functionality then you MUST fill in “e-Mail” field in the sale window. Click License Manager - Search customer toolbar button to perform search of the client through the database. Click License Manager - Generate Unlock Key toolbar button to generate Unlock Key.

License Manager - Real Sale

Click OK to add new sale. Save all changes made in the License Manager. To do it click License Manager - Save all changes toolbar button. All records have been created in the License Manager will be saved in the database.

Your next step depends on if Activation Web Service uses own database, or share database with License Manager. In case when AWS and License Manager are using common database you now can simple use Unlock Key have been created to activate your application. If AWS and License Manager use different databases then you should synchronize data before license can be activated. See “Activation Web Service Management” section for information how to synchronize databases.


Sample written in C#
Sample written in Visual Basic .NET
.NET Licensing Pro Home Page