如何使用微软的Dynamics AX类

本文关键字:AX Dynamics 微软的 何使用 | 更新日期: 2023-09-27 18:26:50

我是报告和 .net 的新手,我已经使用 SSRS 完成了报告,但现在我想将条形码添加到报告中。我已经有一个 Web 服务为我生成条形码图像,但现在只有数据矩阵格式,我想在该 Web 服务中编写该方法,它将为我获取我搜索并遇到的条形码图像或字符串

Microsoft.Dynamics.AX

类,但我不知道如何使用它们msdn也没有提供任何帮助,所以我的问题是

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 ?

我知道有很多第三方工具,但我想知道是否有可能通过自我编码来完成?提前感谢您的帮助。

如何使用微软的Dynamics AX类

1( 是2( 您将需要这些才能从 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;

最后,这是我在 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;
}

然后,要访问AX中的某些功能,您只需要:

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;
    }

最后,如果你想更新一些东西:

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;
            }
        }

但请确保您选择的Something带有.ForUpdate(( 当你计划更新它时。

还必须将计划使用的任何对象添加到应用程序代理(例如 EPApplicationProxies(,并从项目中引用该对象。