Как использовать классы Microsoft Dynamics AX?

Я новичок в отчетности и .net. Я завершил отчет, используя SSRS, но теперь я хочу добавить штрих-код в отчет. У меня уже есть одна веб-служба, которая создает изображение штрих-кода для меня, но только для формата матрицы данных теперь я хочу написать метод в этом веб-сервисе, который даст мне изображение со штрих-кодом или строку, которую я искал и наткнулся на

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 ?

Я знаю, что есть много сторонних инструментов, но мне интересно, можно ли это сделать с помощью самостоятельного кодирования? Заранее спасибо за помощь.


person Community    schedule 08.08.2013    source источник


Ответы (1)


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) и ссылаться на них из своего проекта.

person Kevin DeVoe    schedule 08.08.2013
comment
Какая ссылка на сборку требуется для Dynamics - person ; 09.08.2013
comment
Все в порядке, я понял. Спасибо за помощь . - person ; 09.08.2013