Custom Aif Enhanched inbound port

hi i am getting exception “(Invalid Message schema)” when run services throw batch job.

i am created service service group and then created a inbound port using file adapter.

I have requirement to consume services to insert XML file into table. i am created table with field and written a job to import xml that is working fine.

service class:

class ServiceClass
{
}

[SysEntryPointAttribute(true)]
public void Orders()
{
XmlDocument doc;
XmlNodeList data;
int countinsert;
XmlElement nodeTable;
OrderTable orderTable;
FileIOPermission permissionRead;
#define.filename(@‘C:\AIF\OUT\OrderFile.xml’)
doc = XmlDocument::newFile(#filename);

permissionRead = new FileIOPermission(#filename , ‘r’);
permissionRead.assert();
data = doc.selectNodes(’//Orders’); //
nodeTable = data.nextNode();
ttsBegin;
while(nodeTable)

{
orderTable.UserId = nodeTable.selectSingleNode(“Id”).text();
orderTable.Number = nodeTable.selectSingleNode(“Number”).text();
orderTable.Category = nodeTable.selectSingleNode(“Category”).text();
orderTable.Date = str2DateDMY(nodeTable.selectSingleNode(“Date”).text());
orderTable.Time = nodeTable.selectSingleNode(“Time”).text();

orderTable.insert();
countinsert++;
nodeTable = data.nextNode();
}
ttsCommit;

//info(strFmt("%1 inserted succesfully",countinsert));
}

public static void main(Args _args)
{
ServiceClass Serviceclass = new ServiceClass();
Serviceclass.Orders();

}

if am run this code by job i can successfully import data

my Xml:

<?xml version="1.0" encoding="utf-8"?> 3 001 ABC 03/03/2016 09:30 AM 4 02 XYZ 01/04/2016 09:30 AM

Please help me out what i am missing …

It seems that you don’t understand the purpose of AIF.

If you have a piece of code to import a file, you don’t need AIF at all. You’re basically hard-coding what AIF can do for you in a generic way. If it works for you, just schedule a batch and forget AIF.

If you want to use AIF, you must completely change the Orders() method. It shouldn’t load the file, because that will be done by the file system adapter. You should just define a data contract class and you have to provide data in the right format. Your XML file isn’t formatted as a message for AIF.

Hi Martin,

I have misunderstood the procedure but now as you’ve suggested, I have created a data contract class with all the parm methods as there are fields into my table. but you said that we do not need to load the xml and the file adapter will load it by itself. But how do the adapter knows which file from the In directory it needs to pick for import ?

In my service class, I have cleared all the assignment code and passes the value from xml to parm methods, is this the right approach ? The issue with me is, I have visite so many pages and forums and now it confuses me. if possible please suggest a link where I can find “How to create a custom service to import csv file into AX ?”. Your help will very much appreciated.

Amiga

What files are taken into account is defined by the adapter. The default file system adapter looks for all files in the give folder. When you put new messages to the folder, AIF will automatically process them.

Consult Walkthrough: Exchanging documents by using the file system adapter [AX 2012], for example.

Hi martin,

i am follow the above link to create inbound port. After running the batch job i cant get any any error but when i am looking into

System administration/Periodic/Exception

I get : Invalid Message schema.

System administration/Periodic/Queue Manager

I get : Malformed XML.

now what i am missing can you please tell me my XML is correct or not

It says that the file isn’t in a valid format for AIF. It must be a SOAP message and the body must match the schema of your service. If you’re using a custom service with data contract, the schema of body is derived from the data contract class.

I suggest you first generate an outbound message to check how it looks like.

If you want to use a file of a different format, you can provide a transformation to the format for AIF.

I have replaced my procedure of creating transform assembly to the mentioned link “https://technet.microsoft.com/en-us/library/gg863930.aspx” and my generated xml is same as which is defined as the output xml in the mentioned url. i.e. The customers xml.

Please suggest a way out as things seems correct if I follow the steps mentioned in the technet’s url.

If you still have the same error, you’re still not producing a valid AIF inbound message. If you have a different problem, you’ll have to mention it.