.Net BC Custom App, One Step Back! [Connection]
At the request of one of my readers, let me take a step back and talk about the Business Connector and how to make a successful connection to a Dynamics AX instance through it.
So to set this up let's talk about some important things here. One the Business Connector Proxy. This is the account that is used to start a BC session, in which all "connections" for the shared application pool for IIS go through.
In the EP example you supply this in the Business Connector Proxy form, and then the Applicaiton Pool that is running the SharePoint Portal EP site, Idenity must be the supplied Business Connector Proxy account that was setup in the Dynamics AX form. In our example, we have a standard Application pool. [Because we assume a single site for the IIS, for simple implementation of our custom site.] Since this is the case, then the First person to logon to the custom site can be used as the Business Connector Proxy account, and then all other user connection coming in with use the BC Proxy account, as long as that user account is active and does not time out. If that account does, then the next person to logon will assume the BC proxy account. You can see this in the Online users form. Admin > Online Users.
To achieve this, 2 things must happen. (1) The users using this application must have rights to logon as Business Proxy Account. (2) In your connection code you must make use of a Network credenitals object, and use the LogonAs() method. Let take a look at some sample connection code below:
Example Connection Code:
// Declartions
public Axapta objDAXCn;
System.Net.NetworkCredential nc;
// Make use of Declartions
nc = new System.Net.NetworkCredential(UserId, passwd, NetworkDomain);
objDAXCn = new Axapta();
objDAXCn.LogonAs(userId, NetworkDomain, nc, StartCompany, "", FQAOSInstance, "");
objDAXCn.Refresh();
Session["objDAXCn"] = objDAXCn;
Now lets take and break this down. First we have the declartions. We declar for an Axapta object, and then a NetworkCredential object. These are used as part of forming our connection for the given ASP.net session. Next we take and declare new for the given nc variable and then set it equal to passed in variables. Could be from a login scsreen. The nc is set then, and we move to setting the Connection object [Axapta] to a new instance. Next we perform the .LogonAs() [And not .Logon()] with passing the:
1. userId - From the passed in login screen
2. NetworkDomain - possible Global.asax global variable
3. nc - The given network credentials that will be used for the .Net BC Proxy account. [Unless a session already exists for the instance, then the existing BC Account is made use of]
4. StartCompany - What Dynamics AX company to start in
5. ""
6. FQAOSInstance - The Full name of the Dynamics AX instance. Example: "instanceName@ServerName:PortNumber"
7. ""
After this we perform a refresh and then set a session variable equal to the Open connection so it can be reused throughout the Site session for the given user. [performance helper].
So that is a good breakdown and coverage of making a connection via the .Net BC. YOu can get fancy with this for pooling, multiple Application Pools, single sessions, shared sessions, etc. etc. For now this will give you what you need, and your application should drive you to be as complex, Only as it needs to be. [Always use KISS method]
Well check back as we continue down this path!
Find a job at: www.DynamicsAXJobs.com
So to set this up let's talk about some important things here. One the Business Connector Proxy. This is the account that is used to start a BC session, in which all "connections" for the shared application pool for IIS go through.
In the EP example you supply this in the Business Connector Proxy form, and then the Applicaiton Pool that is running the SharePoint Portal EP site, Idenity must be the supplied Business Connector Proxy account that was setup in the Dynamics AX form. In our example, we have a standard Application pool. [Because we assume a single site for the IIS, for simple implementation of our custom site.] Since this is the case, then the First person to logon to the custom site can be used as the Business Connector Proxy account, and then all other user connection coming in with use the BC Proxy account, as long as that user account is active and does not time out. If that account does, then the next person to logon will assume the BC proxy account. You can see this in the Online users form. Admin > Online Users.
To achieve this, 2 things must happen. (1) The users using this application must have rights to logon as Business Proxy Account. (2) In your connection code you must make use of a Network credenitals object, and use the LogonAs() method. Let take a look at some sample connection code below:
Example Connection Code:
// Declartions
public Axapta objDAXCn;
System.Net.NetworkCredential nc;
// Make use of Declartions
nc = new System.Net.NetworkCredential(UserId, passwd, NetworkDomain);
objDAXCn = new Axapta();
objDAXCn.LogonAs(userId, NetworkDomain, nc, StartCompany, "", FQAOSInstance, "");
objDAXCn.Refresh();
Session["objDAXCn"] = objDAXCn;
Now lets take and break this down. First we have the declartions. We declar for an Axapta object, and then a NetworkCredential object. These are used as part of forming our connection for the given ASP.net session. Next we take and declare new for the given nc variable and then set it equal to passed in variables. Could be from a login scsreen. The nc is set then, and we move to setting the Connection object [Axapta] to a new instance. Next we perform the .LogonAs() [And not .Logon()] with passing the:
1. userId - From the passed in login screen
2. NetworkDomain - possible Global.asax global variable
3. nc - The given network credentials that will be used for the .Net BC Proxy account. [Unless a session already exists for the instance, then the existing BC Account is made use of]
4. StartCompany - What Dynamics AX company to start in
5. ""
6. FQAOSInstance - The Full name of the Dynamics AX instance. Example: "instanceName@ServerName:PortNumber"
7. ""
After this we perform a refresh and then set a session variable equal to the Open connection so it can be reused throughout the Site session for the given user. [performance helper].
So that is a good breakdown and coverage of making a connection via the .Net BC. YOu can get fancy with this for pooling, multiple Application Pools, single sessions, shared sessions, etc. etc. For now this will give you what you need, and your application should drive you to be as complex, Only as it needs to be. [Always use KISS method]
Well check back as we continue down this path!
Find a job at: www.DynamicsAXJobs.com
Labels: .Net, .Net BC, ASP.Net, Business Connector, C#, Dynamics AX
4 Comments:
Thank you for the reply! :)
I'll take a look at that, but from what I understand that way the first user that log in to axapta via BC is always the user that invoke business logic, also for other user in other session. (until the session expire)
Anyway, I'll make some try!
Is it really necessary to use the LogonAs method in ASP.Net? Why can't we just use the Logon method?
jopx,
You do not have to make use of the LogonAs() method, you can use the Logon method. However the issue is the code executing under the Business Connector Proxy vs. the user id context with the LogonAs() method.
There is a way around this, using the RunsAs() within DAX X++ code. Check that out, with the Logon() and you can design your code.. check into it.
-Brandon
It works fine when i use a Asp.net application but when i use it in a webservice it doesn't work.
Post a Comment
<< Home