Ejemplo n.º 1
0
        private static As4Message Read(IOwinRequest request)
        {
            var contentType = ContentType.Parse(request.ContentType);
            var requestMime = MimeEntity.Load(contentType, request.Body);

            return(MimeEntityToAs4Message.Deserialize(requestMime));
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 3
0
        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);
        }