License for Web Service

chrisdfchrisdf Member Posts: 82
edited 2009-07-03 in NAV Three Tier
Hi,

I am developing with an Internet application using web services to write to NAV2009. The web developer has to log into the NAV database and is granted a user license which is relinquished after the web service is complete. If there are no user licenses available then the web application fails to log into NAV.

Does anyone know a way to "allocate" a user license permanently to the web service application so that the web application can always log into NAV ??? A bit like the NAS service that has a user license constantly.

Thanks.

Comments

  • matttraxmatttrax Member Posts: 2,309
    Shouldn't the web service be using a DCO license? And since that is not concurrent it should always be open, if nothing else is using it.
  • chrisdfchrisdf Member Posts: 82
    Hi,

    Thanks for your reply - as I understand it - DCO does not affect user connectivity, it is simply an "honesty" measure.

    I think I have come up with a way to do this - have to keep a table of logins and then control it from Codeunit 1 to error if the number of logins gets to "one less" than the maximum number of licenses available, therefore keeping one license for the middle tier to get in.

    Just seems like something Microsoft would have thought about ... ah well!
  • chrisdfchrisdf Member Posts: 82
    Nope - can't control the user log-in from Codeunit 1, by the time Codeunit 1 is executing, the log in has connected so any statement with an "ERROR" command in it won't work.

    It does seem though that this can be controlled if the database is SQL.

    Section 30.7 of the w1w1adg.pdf outlines how you can create a stored proceedure to execute at log-in time. With the right bit of coding this seems to work. What I did was as follows.

    1. In NAV created some setup fields to hold the max number of licenses and the userid of the web services account.(Table "System Setup" )
    2. Created a new table in NAV to log users connected to the system. (Table "User Log On")
    3. Populated this table from Codeunit 1 (log-in) and deleted the entry from Codeunit 1 (log-out). The web services account should be excluded from logging in this table.
    4. Wrote the stored procedure similar to the example and excluded the web user account from being tested. The SP looks something like this (my SQL coding is not the best but it seems to work!):

    So if the system has 10 licenses, it only allows nine to be used (by accounts other than the web services account).

    USE <DB Name>

    IF EXISTS (SELECT name FROM sysobjects
    WHERE name = 'sp_$ndo$loginproc' AND type = 'P')
    DROP PROCEDURE [sp_$ndo$loginproc]
    GO

    CREATE PROCEDURE [sp_$ndo$loginproc]
    @appname VARCHAR(64) = NULL,
    @appversion VARCHAR(16) = NULL
    AS
    BEGIN
    DECLARE @LicenseCount INT, @AlreadyLoggedIn INT, @WebUserID VARCHAR(30)

    SELECT @LicenseCount = [License Count], @WebUserID = [Web User ID]
    FROM [<DB Name>].[dbo].[ <Company Name>$System Set Up]

    IF suser_sname() <> @WebUserID
    BEGIN
    SELECT * FROM [<DB Name>].[dbo].[User Logon]
    SET @ROWCOUNT
    IF (@LicenseCount - @AlreadyLoggedIn) < = 1
    RAISERROR ('The maximum user count has been reached.', 11, 1)
    END
    END

    GO
    GRANT EXECUTE ON [sp_$ndo$loginproc] TO public
    GO
Sign In or Register to comment.