3

my billing provider needs to get the message in HEX and not in ASCII, for example, I've sent a 800 message and the stream was:

42 00 30 38 30 30 a2 38 00 00 00 80 80 00 04 00

00 00 00 00 00 00 39 30 30 30 30 30 30 34 30 32

31 34 33 31 31 38 31 37 33 31 31 38 31 37 33 31

31 38 30 34 30 32 31 32 33 34 35 36 37 38 39 39

38 30 30 31

Can i use the project to create the message as HEX instead of ASCII? Do i just need to convert the message before i send it (and convert back on return message)?

I'll appreciate your help in the matter

user1308550
  • 31
  • 1
  • 2

2 Answers2

2

You can change the formatters for the fields, bitmap and message types.

Look at the source of the project at the Template class. You need to create your own class that extends Iso8583 and create your own template that has ASCII bitmap and message type formatters.

From the 0.5.1 release you can do the following

public class AsciiIso : Iso8583
{
    private static readonly Template template;

    static AsciiIso()
    {
        template = GetDefaultIso8583Template();
        template.BitmapFormatter = Formatters.Ascii;
        template.MsgTypeFormatter = Formatters.Ascii;
    }

    public AsciiIso() : base(template)
    {
    }
}
John Oxley
  • 14,698
  • 18
  • 53
  • 78
  • It seems the right solution, just to show the desired result, the message I need to send (following my example is something like this:08 00 20 38 00 00 00 80 80 10 90 00 00 54 10 30 17 24 24 04 01 fx fx fx fx fx fx fx fx 09 78 f0 f2 f6 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 so instead of 30 38 30 30 for the 0800 message I need 08 00 (disregard the rest it's arbitrary in my example here). can you provide me with an example? Thanks again! – user1308550 Apr 03 '12 at 14:54
0

What do you mean by "HEX and not ASCII"? A HEX string is usually an ASCII encoded string consisting of [0-9A-F] characters only.

Here is a C# extension method that converts byte arrays into strings of hex-digit pairs representing the bytes of the original byte array:

using System;
using System.Linq;
using System.Text;

namespace Substitute.With.Your.Project.Namespace.Extensions
{
    static public class ByteUtil
    {
        /// <summary>
        /// byte[] to hex string
        /// </summary>
        /// <param name="self"></param>
        /// <returns>a string of hex digit pairs representing this byte[]</returns>
        static public string ToHexString(this byte[] self)
        {
            return self
                .AsEnumerable()
                .Aggregate(
                    new StringBuilder(),
                    (sb, value)
                        => sb.Append(
                            string.Format("{0:X2}", value)
                           )
                ).ToString();
        }
    }
}

Then elsewhere you just use the extension

using Substitute.With.Your.Project.Namespace.Extensions;

and call it like this

aByteArray.ToHexString();

(the code is untested; YMMW)

moosaka
  • 571
  • 5
  • 9