User guide

I promise I will create a more detailed guide very soon, but in the meantime, you can use this basic example to test the functionality of the library. In the source folder, you can find a Console application called ISo4Net.Test. which shows a basic example of reading a fake 0800 message from a byte array and decoding it. By the way, if you have ever worked with jPOS (http://jpos.org), you'll find the same basic concepts.

There are two main functions in the main library objects: Decode() and Encode(). Decode is used to ready a byte array - usually from the network - and translate those bytes into an ISOMessage object. The main component in charge of doing this is the ISOPackager.

ISOPackager is an abstract class, which means that you can't instantiate it directly. You can create your own packager by implementing this class and create your own rules. Anyway, there's already one packager named GenericPackager that reads the Packager rules from an XML file. This XML has the specification of the ISO fields, names, langth and class used to Encode/Decode the data. You can find an example of this file in the Packagers folder (this is the standard definition for ISO8583 '87 ASCII format).

GenericPackager has a couple of interesting properties, HeaderLength that indicated the size of the ISO Header in bytes, and HeaderASCII that indicates if the header can be interpreted as ASCII or not (usefull when dumping the content of the message).

ISOMessage Class

ISOMessage class is the main component to deal with. It has an internal collection of ISOField objects and ISOHeader that represents the required message header, internally stored as a byte array. There're two "special" fields inside the collection. The first is the Primary/Secondary bitmaps, that are always stored in the collection with ID -1; the second is the MTI (Message Type Indicator) that's stored with ID 0.

If you wish, you can take a look at the the code, it's quite simple and you can get a clear understanding of how it works. It's designed to be extensible, so you can create your own classes, with your own logic and plug them in the framework with no effort.

Example

	Console.WriteLine("*** iso4Net Test ***");
	Console.WriteLine("-------------------");

	Console.WriteLine("Reading packager config...");
	string cfgFile = "..\\..\\..\\ISO4Net.Library\\Packagers\\iso87_ascii.xml";

	GenericPackager p = new GenericPackager(cfgFile);
	p.HeaderLength = 3;     // "ISO" word
	p.HeaderASCII = true;

	// *** Authorization example created from scratch ***
	ISOMessage request = p.CreateISOMessage();
	request.Header = new ISOHeader(ASCIIEncoding.ASCII.GetBytes("ISO"));
	request.MTI = "0200";
	request.Add(2, "4444333322221111");
	request.Add(3, "000000");
	request.Add(4, "1000");
	request.Add(7, "0428180300");
	request.Add(11, "000099");
	request.Add(12, "150300");
	request.Add(13, "0428");
	request.Add(14, "1512");
	request.Add(22, "021");
	request.Add(41, "12345678");
	request.Add(42, "88991740");
	request.Add(49, "840");
	request.Add(52, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
	//m.Add(70, "123");

	Console.WriteLine("Encoding 0200 message...");
	byte[] packed200 = request.Encode();
	Console.WriteLine("Encoded HEX:");
	Console.WriteLine(Utils.HexString(packed200));

	Console.WriteLine("\nDump:");
	Console.WriteLine(request.Dump(true));

	Console.WriteLine("\nDecoding back to ISOMessage object:");
	ISOMessage response = new ISOMessage();
	p.Decode(response, packed200);
	Console.WriteLine("Decoding result:");
	response.Dump(true);




Last edited Apr 30, 2014 at 6:51 PM by rbarreiro, version 8