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



Joined: 18 Jul 2005
Posts: 731

Posted: Mon Oct 03, 2011 6:46 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:
Code:
// Standard setup...

CCryptoLicense* lic = new CCryptoLicense();

lic->SetValidationKey(_T("{validation key for your project"));

lic->SetLicenseCode(_T("{a license code generated with a 'Limit Machines To' setting}"));

lic->SetLicenseServiceURL(_T("{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
LPCTSTR paramNames[] = { _T("licenseCode"), _T("settingsFilePath") }; // params

CString licCode ;
licCode= lic->GetLicenseCode();

CString encrStr;
encrStr = lic->EncryptString(licCode);

LPCTSTR paramValues[] = {encrStr , _T("" )}; // param values

CString ret;
ret= lic->QueryWebService(_T("GetCurrentActivations"),   paramNames, paramValues,2);

// Return value is encrypted, decrypt it and show the result
CString decrStr ;
decrStr = lic->DecryptString(ret);

CString result ;
result= _T("CurrentActivations = ")+ decrStr;

AfxMessageBox(result);
Back to top
Display posts from previous:   
Forum Index -> CryptoLicensing For MFC All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group