Question Status

Verified
Eitan Mizrahi asked a question on 19 Mar 2015 10:24 AM

Hello,

I am using dll and do :

Microsoft.Dynamics.ManagedInteroped .Session.Logon.

I want to keep alive the dll, so I won't need to logon every time I use a function in the dll.

That's take a long time consuming every time I do logon as above.

How can this be done?

Thanks :)

Reply
Anton Venter responded on 19 Mar 2015 11:45 AM

Hi Eitan, can you give us more information about how the DLL is used?

Reply
Eitan Mizrahi responded on 19 Mar 2015 12:09 PM

OK.

Here is the code:

using MIL = Microsoft.Dynamics.AX.ManagedInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SPLRestWebLib
{
    public class SPLRestWebBC
    {
        public MIL.Session axSession = null;
        public void connectSession(string env, string lang, string companyName)
        {
//            string s = "";
            if (MIL.Session.Current == null
                        || !MIL.Session.Current.isLoggedOn())
                try
                {
                    // Login to Microsoft Dynamics Ax.
                    axSession = new MIL.Session();
                    axSession.Logon(companyName, lang, env, null);
                    SPLDBHelper.insertLog();
                }
                catch (System.Exception e)
                {
                    Console.WriteLine("An error occurred in object creation or Axapta logon: {0}", e.Message);
                    throw new System.Exception("An error occurred in object creation or Axapta logon: {" + e.Message + "}");
                }
        }

        public string getDisplayMethodValue(string tablename, string methodname, Int64 recid, string dataareaid, int deci, string env = "")
        {
            connectSession(env, "en-us", dataareaid);
            return AXClass.somemethod();
        }
    }
}


connectSession is calling once on the dll lifetime, but when I am using the dll again and again, the logon happens again and again, and I need to do logon once (Steel, I need to use the dll again and again).

I need doing logon once.

How can I do that?

Keep some global variables (but the line 

if (MIL.Session.Current == null
                        || !MIL.Session.Current.isLoggedOn()) 

always returns false, and doesn't use some global variable I can refer to - I need to keep that session somehow always alive. No idea how doing that.


Thanks :)
Reply
Anton Venter responded on 19 Mar 2015 12:37 PM

Since MIL.Session.Current.isLoggedOn() is not working, why don't you check your axSession object instead? If you have logged on successfully, it should be not be null. You can set it to null in the exception handler if the logon attempt fails. Maybe there is a method on the axSession object to check if you are logged in? That will be even better.

Reply
Eitan Mizrahi responded on 19 Mar 2015 12:47 PM

Sorry - isLoggedOn is working and I am logon successfully.

The axSession is not null - I succeed running ax functions with no problem.

(If I calling the function connectSession twice, I logon once).

The problem, that the dll is used the function of mine: getDisplayMethodValue again and again, and once used - the dll is off, and when calling it again, I get into connectSession and logon again. I want to 'keep' that session somehow.

I see a method: InitializeLifetimeService - I don't know whether it is related.

Thanks :)

Reply
Eitan Mizrahi responded on 19 Mar 2015 2:52 PM

Clarification for the code (if I add another  connectSession call):

==========================================

public string getDisplayMethodValue(string tablename, string methodname, Int64 recid, string dataareaid, int deci, string env = "")
        {
            connectSession(env, "en-us", dataareaid); // there is a connect
            connectSession(env, "en-us", dataareaid); // there is no connect
            return AXClass.somemethod();
 
        }
// after this code - dll is off, and when calling again - same scenario - I connect again to ax.


I can have that architecture:

I keep the session in global variable, and when I use the dll again, I can check that global variable and connect with the session-id that I kept in the global variable - I don't know whether possible and how doing that.

But this cause a logon (even in same session), that make take extra time, so better solution is keeping the logon (maybe a windows' service that is always running and using its session).

The goal is to use same function again and again, but logon only once, so I need to figure out what architecture can be done in that case.

The dll is run only in axsvc on the same computer.

Thanks you :)

Reply
Verified Answer
Eitan Mizrahi responded on 20 Mar 2015 1:27 AM

Consider this thread as closed, since I figure out that architecture shall be a listener that starts with logon, and listen to requests.

I shall learn this issue, and I opened a new thread for that.

So, for not doubling this question - I post on:

community.dynamics.com/.../155543.aspx

Thanks anyway :)

Reply
Verified Answer
Eitan Mizrahi responded on 20 Mar 2015 1:27 AM

Consider this thread as closed, since I figure out that architecture shall be a listener that starts with logon, and listen to requests.

I shall learn this issue, and I opened a new thread for that.

So, for not doubling this question - I post on:

community.dynamics.com/.../155543.aspx

Thanks anyway :)

Reply