Labs64 / NetLicensingClient-csharp

C# wrapper for Labs64 NetLicensing RESTful API
https://netlicensing.io
Apache License 2.0
24 stars 16 forks source link

Floating license response isn't available in the validation result #36

Closed r-brown closed 2 years ago

r-brown commented 2 years ago

We have implemented NetLicensingClient-csharp the .Net Client library and we are having issues with floating licenses, it is not showing up on the LicenseeService.validate method we get all the subscription licenses, but the floating license is not returned.

r-brown commented 2 years ago

Validation requests need to contain all attributes required for the validation; such as licenseeNumber Please Note: some licensing models require additional request parameters. For instance, Floating model requires action and sessionId - see more in the NetLicensing Wiki. In the case of malformed request parameters, either the entire validation or specific product modules will become invalid.

NetLicensing's validation response contains the validation per product module.

Below is a typical response where the product is configured with two models: Subscription and Floating.

Every ProductModuleValidation section consists of standard attributes (such as valid or warningLevel) and licensing model-specific attributes (such as expires in case of Subscription).

Request

curl -X POST -H "Authorization: Basic YXBpS2V5OjMyMjdmNTkxLTcyZGYtNGYyYy1hMTZmLTU3ODJmZjQzMTRlNg==" -H "Accept: application/xml" -H "Content-type: application/x-www-form-urlencoded" -d "dryRun=true&productModuleNumber=MIRAAAHX4&action=checkOut&sessionId=session0" https://go.netlicensing.io/core/v2/rest/licensee/CUST-CC-01/validate

Response

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:netlicensing xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:ns2="http://netlicensing.labs64.com/schema/context" ttl="2022-10-12T16:29:33.020Z">
  <ns2:infos/>
  <ns2:items>
    <ns2:item type="ProductModuleValidation">
      <ns2:property name="productModuleNumber">MYYA24YTT</ns2:property>
      <ns2:property name="valid">true</ns2:property>
      <ns2:property name="expires">2022-10-18T07:07:37.465Z</ns2:property>
      <ns2:property name="productModuleName">ABO</ns2:property>
      <ns2:property name="warningLevel">GREEN</ns2:property>
      <ns2:property name="licensingModel">Subscription</ns2:property>
    </ns2:item>
    <ns2:item type="ProductModuleValidation">
      <ns2:property name="productModuleNumber">MIRAAAHX4</ns2:property>
      <ns2:property name="valid">true</ns2:property>
      <ns2:property name="productModuleName">Floating</ns2:property>
      <ns2:property name="warningLevel">GREEN</ns2:property>
      <ns2:property name="licensingModel">Floating</ns2:property>
    </ns2:item>
  </ns2:items>
</ns2:netlicensing>

NetLicensing client libraries replicate this structure in the object structure; see ValidationResult class for the corresponding client library.

C# example

In the case of C# client library, the following code snippet:

String productNumber = "PP2M3U2E7";
String productModuleNumber = "MIRAAAHX4";
String licenseeNumber = "CUST-CC-01";

ValidationParameters validationParameters = new ValidationParameters();
validationParameters.setProductNumber(productNumber);
validationParameters.put(productModuleNumber, "action", "checkOut");
validationParameters.put(productModuleNumber, "sessionId", "session0");

ValidationResult validationResult = null;

// Validate using Basic Auth
context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
validationResult = LicenseeService.validate(context, licenseeNumber, validationParameters);
ConsoleWriter.WriteEntity("Validation result (Basic Auth):", validationResult);

.... returns the object structure as on the screenshot below (Visual Studio debug view)

Screenshot 2022-10-11 at 18 40 45

Resolution

Please make sure, all needed parameters are specified. In the case of the model, please make sure action and sessionId are set:

...
validationParameters.put(productModuleNumber, "action", "checkOut");
validationParameters.put(productModuleNumber, "sessionId", "session0");
...