Multiple login in external application.  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Multiple login in external application.

Postby nexio » Tue Jul 18, 2017 10:25 pm

Hi,

Firstly I would like to thank for all the help we had here, specially from Mike and Stuart. We have built the application in C# and ASP.NET which would create a service manager job.

Although the application works properly for a single user, but when multiple users try to connect simultaneously and access the application:

* When a single user connects to the application, it works and they can read the data and create the job.
* When multiple users, simultaneously connect to the application, they can't access the application and can't read the data. But atleast one user is able to successfully read the data.
* But these multiple users keeps trying again and again, finally they can access the data.

I am guessing that maybe the ASP application is not able to connect to the database with multiple users, simultaneously.

For logging in we have used the following code:
Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Logon("<ServerIP>", "<DatabaseName>", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "adminusername", "adminpassword");


Exception we are getting:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
at JiwaFinancials.Jiwa.JiwaODBC.database.Logon(AuthenticationModes AuthenticationMode, String Name, String Password, Boolean& rtnMustChangePassword, DateTime& rtnPasswordLastChangedDateTime)
at JiwaFinancials.Jiwa.JiwaApplication.Manager.Logon(String ServerName, String DatabaseName, AuthenticationModes AuthenticationMode, String JiwaUserName, String JiwaPassword)

This is the trimmed error, if required, I can strip the confidential information and send the whole error code.

Thanks
nexio
Occasional Contributor
Occasional Contributor
 
Posts: 24
Joined: Thu Jun 08, 2017 6:32 pm

Re: Multiple login in external application.

Postby SBarnes » Wed Jul 19, 2017 8:36 am

Hi Nexio

I had asked Mike this question a while back please refer to this post https://forums.jiwa.com.au/viewtopic.php?f=26&t=611&p=2151&hilit=multiple+login#p2151

But the new methodology of using managers referred to in this post https://forums.jiwa.com.au/viewtopic.php?f=26&t=725 is probably more to what you want as using the instance does not scale well and is really only designed for the one login in the application space.

You would be far better off working with Jiwa's new web API details of which can be found here https://forums.jiwa.com.au/viewtopic.php?f=32&t=775 , the level of functionality that it supports is quite impressive and scales easily and is more suitable for a multi-user web environment. Jiwa have spent a lot of time putting together this API and have done a fantastic job not only in the functionality it provides but in how easy it is to use.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Multiple login in external application.

Postby nexio » Fri Jul 21, 2017 12:10 am

Hi Stuart!

Thanks for your reply. As we go through Consuming the REST API using C Sharp, the link which is provided by you. Can you please let us know the setup process of this. Also can you please let me know what should be add in "provider" under ServiceStack.Client. Also is there any other setup or configuration which needs to be done in visual studio or in Jiwa?

Thanks
nexio
Occasional Contributor
Occasional Contributor
 
Posts: 24
Joined: Thu Jun 08, 2017 6:32 pm

Re: Multiple login in external application.

Postby SBarnes » Fri Jul 21, 2017 7:44 am

Hi Nexio

The first things you need to do are as follows:

1. Configure the self host service ( this is easier than using it hosted in IIS), you do this by editing C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaAPISelfHostedService.exe.config with any text edit to set the server, database, user name and passsword, I also usually change the port to something like 81 instead of 80 just to avoid any web servers

2. Enable the API Plugin in Jiwa under system-> settings-> Plugins -> Plugin Maintenance

3. Exit Jiwa

4. Start the service and check that it is running by opening a browser to localhost:81

5. In your visual studio project use nuget to install the package ServiceStack.Client if you are using Jiwa 7.182 you can use 4.5.12 if you use the latest dev release you need 4.5.13 so you need to add https://www.myget.org/F/servicestack to the package manager sources

6. Now you need the API classes etc go to localhost:81/types/csharp (There is also a link on the default web page for the API) and put this code into your project.

7. You need some code to logon something like this:

Code: Select all
 using (JsonServiceClient client = new JsonServiceClient("URL FOR THE SERVICE HERE"))
                {
                   //Next line only needed if doing a stateful transaction
                   client.Headers.Add("jiwa-stateful", "true");
                    try
                    {
                        var authResponse = client.Send<ServiceStack.AuthenticateResponse>(new ServiceStack.Authenticate()
                        {
                            provider = "credentials",
                            UserName = "admin",
                            Password = "password",
                            RememberMe = true
                        });
                    }
                    catch (WebServiceException ex)
                    {
                        //some error handling here
                        return;
                    }
          }


8. The if you want to do something with a debtor say you do something like this

Code: Select all
                    try
                    {

       
                         DebtorGETRequest debtorreq = new DebtorGETRequest();
                         debtorreq.DebtorID = "00000000080000000002";
                         Debtor debtor = client.Get<Debtor>(debtorreq);
                         DebtorDirector director = new DebtorDirector();
                         director.Name = "Mike Sheen";
                         director.Address = "Jiwa";
                         director.OfficeHeld = "Chief Software Engineer";
                         debtor.Directors.Add(director);
                         DebtorPATCHRequest patch1 = debtor.ConvertTo<DebtorPATCHRequest>();

                         patch1.Name = debtor.Name + " Added to company name";
                         Debtor debtor2 = client.Patch<Debtor>(patch1);



                         DebtorSAVERequest savereq = debtor2.ConvertTo<DebtorSAVERequest>();

                         debtor = client.Get<Debtor>(savereq);

                        LogoutGetRequest logout = new LogoutGetRequest();
                        LogoutGetResponse lresp = client.Get<LogoutGetResponse>(logout);



                    }
                    catch (WebServiceException ex)
                    {

                        //Error Handling goes here

                        return;
                    }


That should be enough to get you started, you can also add to the API by having your own plugin, which is in the documentation.

If you are new to ServiceStack there is short book found here https://www.syncfusion.com/resources/techportal/details/ebooks/servicestack that should explain the concepts.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Multiple login in external application.

Postby nexio » Fri Jul 21, 2017 11:22 pm

Hi Stuart,

Thanks for your reply. Quick question.
Do we need to create a user for API in jiwa, if yes then how can we assign them privilege for accessing information in jiwa or is there already a user in jiwa for API?

Thanks
nexio
Occasional Contributor
Occasional Contributor
 
Posts: 24
Joined: Thu Jun 08, 2017 6:32 pm

Re: Multiple login in external application.  Topic is solved

Postby SBarnes » Sat Jul 22, 2017 7:43 am

HI Nexio

When I posted the last reply I had a feeling I had let something out, if you are working with a Jiwa Demo Database there is a user called api that can be used to start the service and be the user named in the config file for the service.

As for logging in from the code that can be any user but you need to set the appropriate permissions for the user group that user you are using belongs to go to System Settings - > Staff Configuration -> User Group Maintenance -> REST API Tab to set individual paths such as /Debtors or Set the default REST Permission to Allow but bear in mind this turns on the entire API, so it's probably OK for development but not for production.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Multiple login in external application.

Postby nexio » Sat Jul 22, 2017 9:11 pm

Hi Stuart,

Thanks for replying.

The API looks very promising and we were very hopeful, but unfortunately our client is using 7.0.157 version and we cannot use API till it is upgraded. We were thinking of finding a workaround till then.

Thanks
nexio
Occasional Contributor
Occasional Contributor
 
Posts: 24
Joined: Thu Jun 08, 2017 6:32 pm

Re: Multiple login in external application.

Postby SBarnes » Sun Jul 23, 2017 8:12 am

Hi Nexio,

The only suggestion I can make down that path would be for you to attempt to develop you own ServiceStack Self Hosted Service to provide similar functionality that could be integrated as an API plugin later or upgrade the current version now or find out from Mike when the next release will be.

If you developed your own service you could use ORMLite to retrieve most of the data you need from the database and then only use the Jiwa objects when you need to write to the database i.e. logon before and log off after the operation is completed but is would have limited scalability at best.

If the current version of Jiwa uses any plugins these would possibly need some rework but having done this process a couple of times on some fairly large plugins it doesn't take a huge amount of time.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Multiple login in external application.

Postby Mike.Sheen » Mon Jul 24, 2017 11:26 pm

Hi nexio,

Is it possible for you to provide a sample application which exhibits this problem? Without seeing how you're performing session and user management in your application, it's hard for me to provide any guidance.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 1 guest