Reputation:
I am new to the reporting and .net I have completed report using the SSRS but now i want to add the Barcode into the report.I already have one web service which is generating the Barcode image for me but for only data-matrix format now i want to write the method in that web service which will get me the Barcoded image or string I have searched and came across the
Microsoft.Dynamics.AX
Classes but i have no idea how to use them msdn also not provided any help with it so my questions are
1) Is it possible to use the Microsoft.Dynamics.AX classes in to the web service?
2) If possible how to add references any links will be helpful ?
3) If not then any other way for it ? any links will be helpful ?
I know there is lot's of third party tools but i am wondering whether is it possible to do it by self coding ?Thanks for the help in advance .
Upvotes: 3
Views: 2141
Reputation: 602
1) Yes 2) You'll need these to access information from within AX.
using Microsoft.Dynamics.AX.Framework.Linq.Data;
using U23 = Microsoft.Dynamics.AX.ManagedInterop;
using U22 = Microsoft.Dynamics.AX.Framework.Linq.Data;
using Microsoft.Dynamics.Portal.Application.Proxy;
Finally, here is my basic layout of my access layer in C#.
private U23.Session _axSession = new U23.Session();
public U23.Session Connection
{
get
{
return this._axSession;
}
}
/// <summary>
/// Checks to see if the AX session is connected. If it's null we return false.
/// Then we check to see if it's logged in, then return true. Otherwise it's not logged in.
/// </summary>
public bool Connected
{
get
{
if (this._axSession == null)
{
return false;
}
else if (this._axSession.isLoggedOn())
{
return true;
}
return false;
}
}
/// <summary>
/// This connects to the AX session. If it's already connected then we don't need to connect
/// again, so we return true. Otherwise we'll try to initiate the session.
/// </summary>
/// <returns>
/// True: Connection openned successfully, or was already open.
/// False: Connection failed.
/// </returns>
public bool OpenConnection()
{
if (this.Connected)
{
return true;
}
else
{
try
{
_axSession.Logon(null, null, null, null);
return true;
}
catch
{
return false;
}
}
}
/// <summary>
/// If the session is logged on we will try to close it.
/// </summary>
/// <returns>
/// True: Connection closed successfully
/// False: Problem closing the connection
/// </returns>
public bool CloseConnection()
{
bool retVal = false;
if (this.Connection.isLoggedOn())
{
try
{
_axSession.Logoff();
retVal = true;
}
catch
{
retVal = false;
}
}
else
{
retVal = true;
}
this.Connection.Dispose();
return retVal;
}
Then to access certain functions in AX you'll just need to:
public Somethings GetSomethingsById(int id)
{
Somethings retVal = new Somethings();
U22.QueryProvider provider = new U22.AXQueryProvider(null);
U22.QueryCollection<Somethings> somethings = new U22.QueryCollection<Somethings>(provider);
var somethings2 = somethings.Where(x => x.SomethingId == id);
retVal = somethings2.FirstOrDefault();
return retVal;
}
Finally, if you want to update something:
public bool UpdateSomething(Something something)
{
U23.RuntimeContext.Current.TTSBegin();
try
{
if (something.Count == 0)
{
something.Delete();
}
something.Update();
U23.RuntimeContext.Current.TTSCommit();
return true;
}
catch
{
U23.RuntimeContext.Current.TTSAbort();
return false;
}
}
but make sure you're selecting your Something
with .ForUpdate() when you plan on updating it.
You'll also have to add any of objects you plan on using to an Application Proxy (such as EPApplicationProxies) and reference that from your project.
Upvotes: 2