Example #1
0
        private static Task WriteAsync(As4Message message, IOwinResponse response)
        {
            var responseMime = As4MessageToMimeEntity.Serialize(message);

            response.ContentType = responseMime.ContentType.MimeType + responseMime.ContentType.Parameters;
            return(responseMime.WriteToAsync(response.Body, true));
        }
Example #2
0
        public As4Message Send(Uri uri, As4Message message)
        {
            var mimeMessage = As4MessageToMimeEntity.Serialize(message);

            var request = (HttpWebRequest)WebRequest.Create(uri);

            request.Method      = "POST";
            request.ContentType = mimeMessage.ContentType.MimeType + mimeMessage.ContentType.Parameters;

            if (Certificate != null)
            {
                request.ClientCertificates.Add(Certificate);
            }

            using (Stream requestStream = request.GetRequestStream())
            {
                mimeMessage.WriteTo(requestStream, true);
            }

            var response = (HttpWebResponse)request.GetResponse();

            if (string.IsNullOrEmpty(response.ContentType))
            {
                return(null);
            }

            var contentType = ContentType.Parse(response.ContentType);

            using (Stream responseStream = response.GetResponseStream())
            {
                var mimeEntity = MimeEntity.Load(contentType, responseStream);
                return(MimeEntityToAs4Message.Deserialize(mimeEntity));
            }
        }
        private void CheckSerialization(Envelope envelope, params Attachment[] attachments)
        {
            var message     = Messages.Create(envelope, attachments);
            var mimeEntity  = As4MessageToMimeEntity.Serialize(message);
            var contentType = mimeEntity.ContentType;
            var stream      = new MemoryStream();

            mimeEntity.WriteTo(stream, true);
            stream.Position = 0;
            var decodedEntity  = MimeEntity.Load(contentType, stream);
            var decodedMessage = MimeEntityToAs4Message.Deserialize(decodedEntity);

            MessageAssert.AreEqual(message, decodedMessage);
        }