Sky Software Homepage LogicNP Software Knowledge Base And FAQ

 
Contact Product Support    SearchSearch      Subscribe to the RSS feed for this forum

HOWTO: Create custom license service methods

 
Subscribe to the RSS feed for this forum  Forum Index -> CryptoLicensing For ActiveX
View previous topic :: View next topic  
Author Message
Support



Joined: 18 Jul 2005
Posts: 731

Posted: Mon Oct 03, 2011 6:24 am    Post subject: HOWTO: Create custom license service methods

You can create and add your own methods to the default set of license service methods. These custom methods can be called from your software using the CryptoLicense.QueryWebService method. The following demonstrates how to add a custom method which retrieves the number of activations remaining for a license:

In the App_Code/LicenseService.cs or App_Code/LicenseService.vb file of your license service, add following method to LicenseServiceClass :
[C#]
Code:
// The custom method must be marked with a "WebMethod" attribute and must have a return type of "string"
[WebMethod]
public string GetCurrentActivations(string licenseCode, string settingsFilePath)
{

string ret = "";

try
{

this.Initialise(settingsFilePath);
// Decrypt license code
licenseCode = this.Generator.DecryptString(licenseCode);
CryptoLicense lic = new CryptoLicense(licenseCode, this.Generator.GetValidationKey());

if (lic.ValidateSignature())
{
ret = this.GetNumberOfActivations(lic, "", "").ToString();
}

}
catch { }

// Return result in encrypted form for security.
return this.Generator.EncryptString(ret);

}


[VB.Net]
Code:
' The custom method must be marked with a "WebMethod" attribute and must have a return type of "string"
<WebMethod> _
Public Function GetCurrentActivations(licenseCode As String, settingsFilePath As String) As String

   Dim ret As String = ""

   Try

      Me.Initialise(settingsFilePath)

      ' Decrypt license code

      licenseCode = Me.Generator.DecryptString(licenseCode)

      Dim lic As New CryptoLicense(licenseCode, Me.Generator.GetValidationKey())

      If lic.ValidateSignature() Then

         ret = Me.GetNumberOfActivations(lic, "", "").ToString()

      End If

   Catch
   End Try

   ' Return result in encrypted form for security.
   Return Me.Generator.EncryptString(ret)

End Function


You can then call this method from your software as follows:
[VB6]
Code:
' Standard setup...
lic.ValidationKey = "{validation key for your project"

lic.LicenseCode = "{a license code generated with a 'Limit Machines To' setting}"

lic.LicenseServiceURL = "{url of your license service}"

' Call the custom "GetCurrentActivations" web method.

' The license code can be sent in encrypted form using EncryptString method for security

Dim paramNames(1) As String
' params
paramNames(0) = "licenseCode"
paramNames(1) = "settingsFilePath" ' params

' param values
Dim paramValues(1) As String
paramValues(0) = lic.EncryptString(lic.LicenseCode)
paramValues(1) = ""

Dim ret As String
ret = lic.QueryWebService("GetCurrentActivations", paramNames, paramValues)

' Return value is encrypted, decrypt it and show the result
MsgBox ("CurrentActivations = " + lic.DecryptString(ret))
Back to top
Display posts from previous:   
Forum Index -> CryptoLicensing For ActiveX All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group