July 26, 2012

Top 5 AIF Development Tips and Tricks

Top 5 AIF Development Tips and Tricks
1. Enable the debugger
You will notice, if you put a breakpoint into your document class, that when you run the associated action, the breakpoint will get ignored – leaving you in the dark. This is because the action is called using a ‘runas’ function call  to change the user executing the code.
To workaround this replace the runas method calls with direct calls in\Classes\AifOutboundProcessingService\ and \Classes\AifInboundProcessingService, eg:
1 /*
2 runas(message.sourceEndpointAxUserId(),
3 classnum(AifInboundProcessingService),
4 staticmethodstr(AifInboundProcessingService, processAsUser),
5 [message.pack(), messageId]);
6 */
7 AifInboundProcessingService::processAsUser([message.pack(), messageId]);

2. Run jobs instead of waiting for batch processing
The usual way for the AIF to run is using the batch processing framework, where you setup an interval for the inbound and outbound processing  to run.  This minute or so can feel like an age when you are in the middle of developing:
clip_image002
AIF batch processing
So use a custom job to have the AIF run instantly at the click of a button, here is an example of the receive job:
01 static void runAIFReceive(Args _args)
02 {
03 AifGatewayReceiveService aifGatewayReceiveService;
04 AifInboundProcessingService aifInboundProcessingService;
05 ;
06
07 aifGatewayReceiveService = new AifGatewayReceiveService();
08 aifGatewayReceiveService.run();
09 aifInboundProcessingService = new AifInboundProcessingService();
10 aifInboundProcessingService.run(true);  // pass true for debug mode
11 }

3. Use file adapters
clip_image004
When using the AIF, you will most likely be using a Biztalk, Web service or MSMQ adapter. Testing actions using one of these adapters can be a pain as you will most likely require another program to send or receive the message.
To get around this you can use a file adapter during testing, so that you can just write the message in plain XML and drop the file into a directory on your file system to be processed.
Then when you are finished testing / developing you can easily swap the file adapter out.
4. Compose messages with the Visual Studio XML editor
During development (when you use a file adapter), you can create the message using notepad or any other text editor. I recommend using the Visual Studio XML editor to quickly compose these to take advantage of intellisense, schema validation and other useful features (like inserting a guid):
clip_image006
5. Use the pipeline
It is unlikely (if you are integrating with a third party) that the XML schemas  of the external system match those in AX.
To transform the message into the format AX can handle you can use the pipeline to add a component to run an xslt on the inbound XML:
clip_image008


Enjoy...
Harry

No comments:

Post a Comment

Thanks

Note: Only a member of this blog may post a comment.