So while working on the last post I ran into an issue where I couldn't change which aos the data was being pulled in from so I wrote the following function that gets server information so you can see basic information on what connection is being used. Along with defining which AOS the code pulls from by defining a server within code so I can switch back and forth between DEV & TEST
You can download the C# visual studio project here: download now!
Its good to note that around the web the following "logon" statement is posted
// Logon to Dynamics AX
Session axSession = new Session();
axSession.Logon(null, null, null, null);
However in order to define which AOS server to connect to via code we need to do the following
// Logon to Dynamics AX
Session axSession = new Session();
axSession.Logon(null, null, "AOSServerName", null);
The following code are just some ways to pull in basic server information
private void GetAOSInfo_Click(object sender, EventArgs e)
{
try
{
// Logon to Dynamics AX
Session axSession = new Session();
axSession.Logon(null, null, axServerName, null);
//get server information
string axInfoAOSInstance = axSession.CreateObject("XSession").Call("AOSName").ToString();
string axInfoClientName = axSession.CreateObject("XSession").Call("clientComputerName").ToString();
string axInfoLoginDateTime = axSession.CreateObject("XSession").Call("loginDateTime").ToString();
string axInfoMasterSessionId = axSession.CreateObject("XSession").Call("sessionId").ToString();
string axInfoUserId = axSession.CreateObject("XSession").Call("userId").ToString();
CustomerOutput.Clear();
CustomerOutput.AppendText(("AOS Server: " + axInfoAOSInstance));
CustomerOutput.AppendText((Environment.NewLine + "Client Computer Name: " + axInfoClientName));
CustomerOutput.AppendText((Environment.NewLine + "Session Id: " + axInfoMasterSessionId));
CustomerOutput.AppendText((Environment.NewLine + "Login DateTime: " + axInfoLoginDateTime));
CustomerOutput.AppendText((Environment.NewLine + "User Id: " + axInfoUserId));
//log off ax
axSession.Logoff();
}
catch (Exception ex)
{
CustomerOutput.Clear();
CustomerOutput.AppendText(ex.Message.ToString());
}
}
No comments:
Post a Comment