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)

changeCompany in C#

(0) ShareShare
ReportReport
Posted on by

Hi!

I have project in C# which take some data from AX...

Project doesn't use crossCompany ability and i dont want to refactor whole solution to use it...

Changing company is made by Logoff and Logon...

public void SetCompany(string companyId)
        {
            AXSession.Logoff();
            AXSession.Logon(companyId, null, ConfigurationManager.AOSAddress, null);
        }

This approach made this solution is very slow... and im looking for some clever concept.

Do you have idea how to do this ??

Is it possible to permanetly change company... 

Thank you in advance!

*This post is locked for comments

I have the same question (0)
  • Vilmos Kintera Profile Picture
    46,149 on at

    You may call static class methods from C# just fine. Put your changeCompany code block around the functionality which you want to run within Dynamics AX X++ in that method, problem solved.

    msdn.microsoft.com/.../aa860755.aspx

  • Community Member Profile Picture
    on at

    You showed me X++ code... But in C# this functionality wouldnt work...

    I can  only CallStaticClassMethod but i can't indicate piece of sourcecode which should work inside...

    If i have Microsoft.Dynamics.AX.ManagedInterop.Session  session i could only call:

    session.CallStaticClassMethod("Global", "changeCompany" , "CompanyId"); where should i put source code which will run in CompanyId ??

  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    By the way, it seems that you're still using Business Connector, despite the fact that it doesn't exist in AX 7 and therefore you won't be able to upgrade your solution. Changing the architecture to web services would be allow you to upgrade, you could easily set the company through CallContext and you wouldn't have any performance problems with logging in.

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    You missed my point. You should do it in X++ for the business logic that you want to invoke from outside, you cannot change company within C# since the session manager is bound to the company context which you have passed in.

    So if you call a method like "thisismymethod" in "thisismyclass" class as a static call, you'd do the changecompany in X++ within thisismymethod. There are no other workarounds, since the changecompany is only true for the scope of the code block inside that calls' braces.

  • Community Member Profile Picture
    on at

    Oooo this is very bad information :( I didnt know that AX7 not supporting BC... AX7 is a vision of future for company that i work for... but it will be nice if my solution would work fine after upgrade... Do you know some good documentation how to use Web Services instead of BC ?? Most of information is focused on use Web Services in AX... But i need to use it from AX :)

  • Vilmos Kintera Profile Picture
    46,149 on at

    You are now diverting from the original topic. If you have found a helpful answer, mark those as read, and for new questions open a new thread please.

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    I've collected some links at Docs.com: Microsoft Dynamics AX 2012: AIF and Web Services. Note that AIF document services don't exist in AX 7 either (they've been replaced with data entities exposed through OData), therefore you would have to rework your solution during upgrade anyway (but at least you would already have a document-oriented architecture). If your solution is a good candidate for custom services (which may be the case, if you chose BC before instead of document services), you'll be able to use your custom services in AX 7 too with almost no changes.

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans