web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Using AX Business connector in dll.

(0) ShareShare
ReportReport
Posted on by

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 :)

*This post is locked for comments

I have the same question (0)
  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at

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

  • Community Member Profile Picture
    on at

    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 :)
  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at

    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.

  • Community Member Profile Picture
    on at

    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 :)

  • Community Member Profile Picture
    on at

    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 :)

  • Verified answer
    Community Member Profile Picture
    on at

    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 :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans