web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

CRUD via Web Services to C#

(0) ShareShare
ReportReport
Posted on by

Hi!

I need to handle CRUD operations on AX (custom) Tables from .NET aplication...

Read i managed via QueryService which is embeded in AX... It return me System.Data.DataSet and its easy to manage in C#

Problem appears when i want to handle other operations...

What is the best way ??

Can i use some embeded service or should i create new service (different for each table o mayby generic) ??

Thank you in advance! 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,908 Most Valuable Professional on at

    The Query service, as its name suggests, is only for querying. I suggest you look at AIF document services instead.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    You could use the AX Application Integration Framework (AIF) Document Services for that. There are a couple of documents available out-of-the-box, and you could easily create the rest with a wizard yourself.

    technet.microsoft.com/.../aa859008.aspx

  • Community Member Profile Picture
    on at

    I'm familiar with AIF document services but i have one problem with it... It seperate logic between AX and other system...

    I'm looking for solution which is resizable... with document service i need to generate classes, queries, macros, etc. to manage every table... Is tere any solution to do it generic ?? Once for all tables ??

    For Read operation QueryService works fine because i create query in C# and execute them...

  • Vilmos Kintera Profile Picture
    46,149 on at

    There is no generic solution, you already have what is viable.

    I have a different point of view on this, how I see is that you only have to build the interfaces using the document services for your tables once (or custom AIF services for a concrete operation), then you may easily have N number of different systems talking to AX through the same ports be it BizTalk, .Net apps or services, whatsoever which can consume WCF web services.

  • Verified answer
    Martin Dráb Profile Picture
    237,908 Most Valuable Professional on at

    Actually document services have many more features. They're about documents, not just tables, when one logical document can consist of several tables (such as orders have headers, lines, attached notes etc.). You can configure which fields will be exposed, which will be mandatory, add any business logic to the document classes and so on.

    Also, having strongly-types C# classes for your documents makes development of client applications very productive and the compile-time control can prevent many errors.

    If you want to give up these features for a generic solution, document services offer AifGenericDocumentService. Or you can do anything you like in custom services.

    The query services clearly doesn't meet your requirements, as you need more than just querying.

  • Community Member Profile Picture
    on at

    What do you think about this soultion ??

    [SysEntryPointAttribute(false)]
    public Common GetCommon(str _tableName, str 20 _recId, str _dataAreaId)
    {
        TreeNode treeNode;
        SysDictTable sdt;
        Common com;
    
        treeNode = TreeNode::findNode(@'\Data Dictionary\Tables\' + _tableName);
        if (treeNode )
            sdt = new SysDictTable(tableName2Id(_tableName));
        com = sdt.makeRecord();
    
        select firstOnly com where com.RecId == str2int64(_recId);
        return com;
    }
    
    [SysEntryPointAttribute(false)]
    public void SetCommon(str _tableName, str 20 _recId, str _dataAreaId, Common _record)
    {
        TreeNode treeNode;
        SysDictTable sdt;
        Common com;
    
        treeNode = TreeNode::findNode(@'\Data Dictionary\Tables\' + _tableName);
        if (treeNode )
            sdt = new SysDictTable(tableName2Id(_tableName));
        else
            return;
        com = sdt.makeRecord();
        
        select forUpdate firstOnly com where com.RecId == str2int64(_recId);
        ttsBegin;
        buf2Buf(_record, com);
        com.update();
        ttsCommit;
    }
  • Verified answer
    Martin Dráb Profile Picture
    237,908 Most Valuable Professional on at

    It's possible, but it's not that simple - that there are many things to fail. For example, you ignore update conflicts, so you can easily override somebody else's changes and get your DB to an inconsistent state. Or how the performance will look like if somebody uses it for tables without an index over RecId? You also don't check whether the select returns anything (calling update() makes no sense in such as case), you don't call validateWrite(), it's not clear how you intend to deal with security (user have no permissions to write, there is XDS in place...), you start transaction only after selecting a record which will fail with pessimistic locking...

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    It looks like a good idea to me. But do not forget to call if (common.validateWrite()) { common.update(); }

    The LCS Code Analysis tool does raise an error if you do not do this.

    Edit: Martin has spotted the same issue :)

  • Community Member Profile Picture
    on at

    I know that this solution may cause bugs... But i will use this service to CRUD only tables which are used for integration between systems... This are tables which was created by me... and nobody else will CRUD on it... only events which create records...

    My .NET application only CRUD on records which won't be CRUD by AX...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans