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 .Net
View previous topic :: View next topic  
Author Message
Support



Joined: 18 Jul 2005
Posts: 731

Posted: Thu Jul 08, 2010 5:49 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:
[C#]
Code:
// Standard setup...

CryptoLicense lic = new CryptoLicense();

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

string ret = lic.QueryWebService("GetCurrentActivations",

new string[] { "licenseCode", "settingsFilePath" }, // params

new string[] { lic.EncryptString(lic.LicenseCode), "" } // param values

);

// Return value is encrypted, decrypt it and show the result

MessageBox.Show("CurrentActivations = " + lic.DecryptString(ret));


[VB.Net]
Code:
' Standard setup...

Dim lic As CryptoLicense = New CryptoLicense()

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() As String = {"licenseCode", "settingsFilePath"} ' params
Dim paramValues() As String = {lic.EncryptString(lic.LicenseCode), ""} ' param values

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

' Return value is encrypted, decrypt it and show the result

MessageBox.Show("CurrentActivations = " + lic.DecryptString(ret))
[/b]
Back to top
Display posts from previous:   
Forum Index -> CryptoLicensing For .Net All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group