Example #1
0
        public static string Serialize(RequestMessage message)
        {
            // Use the serializer.

            var serializer = new SecurePaySerializer(message.GetType());

            using (var stream = new MemoryStream())
            {
                serializer.WriteObject(stream, message);
                stream.Position = 0;

                using (var reader = new StreamReader(stream))
                {
                    return(reader.ReadToEnd());
                }
            }
        }
Example #2
0
        private static PaymentResponseMessage <TResponseTxn> DeserializeWithSerializer <TResponseTxn>(string message)
            where TResponseTxn : PaymentResponseTxn, new()
        {
            var serializer = new SecurePaySerializer(typeof(PaymentResponseMessage <TResponseTxn>));

            byte[] bytes;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(message);
                }

                bytes = stream.GetBuffer();
            }

            using (var stream = new MemoryStream(bytes))
            {
                return((PaymentResponseMessage <TResponseTxn>)serializer.ReadObject(stream));
            }
        }