c# - 如何使用微软的 Dynamics AX 类?

标签 c# web-services reporting-services axapta

我是报告和 .net 的新手 我已经使用 SSRS 完成了报告,但现在我想将条码添加到报告中。我已经有一个生成条码图像的网络服务对我来说,但现在只针对数据矩阵格式,我想在该 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 ?

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

最佳答案

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

但请确保在计划更新时使用 .ForUpdate() 选择您的 Something

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

关于c# - 如何使用微软的 Dynamics AX 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18130168/

相关文章:

java - 什么是 .episode 文件..?

c# - DefiningQuery 且 <ModificationFunctionMapping> 元素中不存在 <DeleteFunction> 元素以支持当前操作

c# - 线程顺序执行?

c# - C#如何根据外部条件使用线程处理标志

java - 在 Netbeans 中生成 WSDL 时出错

asp.net - 如何使用 web 服务返回接口(interface)或 "complex"值?

c# - System.Text.RegularExpressions.Regex.Matches 的性能特征 - 一个错误?

reporting-services - 如何通过 SSRS Web 服务获取报告 URL?

reporting-services - 在 SSRS 中传递参数

visual-studio-2010 - 如何格式化报告中的日期以完全符合我的要求 - RDLC