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)

AIF Custom Service with File Adapter

(0) ShareShare
ReportReport
Posted on by

Hello

I have created a custom service in AX 2012 R3.  I created the required data contracts and the service works fine when called via a C# webservice.

However I need to call this service based on input XML files using the file system adapter.  For some reason the XML does not get deserialized and the the data contract is null when the service class is called.  

Has anyone done this or something similar?  Is it possible to invoke a custom service with a data contract using the file system adapter?

 

*This post is locked for comments

I have the same question (0)
  • Mea_ Profile Picture
    60,284 on at

    Hi rthomsen,

    When you are using file system adapter AX pick files from a folder put them into que and process. Do you want to trigger this process from c# application ? What is wrong with standard batch job that usually does this ?

  • rthomsen Profile Picture
    on at

    Sorry, you are misunderstanding.  I set up my inbound service using a nettcp port and tested it by calling it from a C# application.  It worked.

    Now I want to call the service based on an XML input file instead so I created an inbound file adapter port for the same service.  The XML is read into AX and the service class is invoked but the XML data is not passed in.

  • Faisal Fareed Profile Picture
    10,796 User Group Leader on at

    Hi,

    XML file has to be in correct format as per AX services standard, make sure it is in correct format with all required header, body and footer section. Please read through from there to get more idea. https://shashidotnet.wordpress.com/2011/12/11/dynamics-ax-2012-aif-import-csv-file-part-2-create-item-from-file-adapter/

  • mail2vd Profile Picture
    1,330 on at

    Hi,

    follow the link what Faisal has mentioned. Also make sure that you pass the elements in exactly the same order as what xml is asking for.

    I used to get the CSV file from customer and i need to convert into XML message which is understand by AIF service. somewhere in C#, i was reading the fields in a different order than what xml is needed and it just never transformed to XML.

  • rthomsen Profile Picture
    on at

    In the link provided a standard document service is being used and not a custom service with data contracts.  Just to keep it as simple as possible I tried the following input XML:

    <?xml version="1.0" encoding="utf-8" ?>

    <Envelope xmlns="schemas.microsoft.com/.../Message&quot;>

       <Header>

    <MessageId>3fc1c177-d1c7-49c0-ad11-e74b6238c20e</MessageId>

    <Action>tempuri.org/.../customTest&lt;/Action>

       </Header>

       <Body>

           <MessageParts>

    <testData>testString</testData>

          </MessageParts>

     </Body>

    </Envelope>

    With this custom service class :

    [SysEntryPointAttribute(true)]

    public void customTest(str testData)

    I still don't get anything passed into my custom service

  • rthomsen Profile Picture
    on at

    After trying numerous things, I don't think is possible.  My work around is to deserialize the xml in an inbound pipeline and do all of the custom service logic there.  The service class is just a dummy implementation.  I would still be interested to hear if anyone else has had success with inbound custom services using file or MQ adapters.

  • Suggested answer
    Dmitry Begun Profile Picture
    20 on at

    Hello

    yes, you can do that. See an example of service operation and XML file.

    A service class and data contracts:

    // custom service class
    class MyInventoryOnhandService
    {
        [
            SysEntryPointAttribute,
            AifCollectionTypeAttribute('return', Types::Class, classStr(MyInventoryOnhandResponse))
        ]
        public List read(MyInventoryOnhandRequest _request)
        {
            ...
        }
    }

    // data contract classes
    [DataContractAttribute('Request')]
    class MyInventoryOnhandRequest
    {
        [
            DataMemberAttribute('Data'),
            AifCollectionTypeAttribute('_items', Types::Class, classStr(MyInventoryOnhandRequestItem)),
            AifCollectionTypeAttribute('return', Types::Class, classStr(MyInventoryOnhandRequestItem))
        ]
        public List parmItems(List _items = items)
        {
            ...
        }
        
        [DataMemberAttribute('RequestType')]
        public String20 parmRequestType(String20 _requestType = requestType)
        {
            ...
        }    
    }

    [DataContractAttribute('Sku')]
    class MyInventoryOnhandRequestItem
    {
        [DataMemberAttribute('MtrxCode1')]
        public ColourName parmColour(ColourName _colour = colour)
        {
            ...
        }
        
        [DataMemberAttribute('MtrxCode2')]
        public SizeName parmSize(SizeName _size = size)
        {
        ...
        }    
            
        [DataMemberAttribute('Product')]
        public ItemId parmItemId(ItemId _itemId = itemId)    
        {
            ...
        }
    }

    Inbound AIF port (FileAdapter) name: MyInventoryOnhand

    Inbound XML file sample:

    <Envelope xmlns="schemas.microsoft.com/.../Message">
        <Header>
            <Action>schemas.microsoft.com/.../read&lt;/Action>
        </Header>
        <Body>
            <MessageParts xmlns = "schemas.microsoft.com/.../Message">
                <_request xmlns = "schemas.microsoft.com/.../services"
                          xmlns:a="schemas.datacontract.org/.../Dynamics.Ax.Application"
                          xmlns:i="www.w3.org/.../XMLSchema-instance">
                    <a:Data>
                        <a:Sku>
                            <a:MtrxCode1>Blue</a:MtrxCode1>
                            <a:MtrxCode2>10</a:MtrxCode2>
                            <a:Product>B_SAMPVEST</a:Product>
                        </a:Sku>
                    </a:Data>
                    <a:RequestType i:nil="true"/>
                </_request>
            </MessageParts>
        </Body>
    </Envelope>

  • Sumit Bhagat Profile Picture
    121 on at

    Hi Dmitry,

    I did create a custom AIF service with file system adapter using dataContract and Service class. I am even able to create proper XML file to import from the inbound repository. I used contract class as a parameter for the service operation. Now, here is the part where my code is failing. I am getting null contract class inside service operation. I did mentioned AifCollectionTypeAttribute for contract class before operation method. Do you have any idea why am I getting null parameter object of contract class?

    Thank you.

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