private void CheckSigning(Envelope envelope, params Attachment[] attachments) { var xml = ObjectToXml.Serialize(envelope); var ebmsSigner = new EbmsSigner { Xml = xml, Certificate = Certificates.CreateSelfSigned(), Uris = new [] { envelope.Header.Messaging.Id, envelope.Body.Id }, Attachments = attachments }; ebmsSigner.Sign(); var ebmsVerifier = new EbmsVerifier { Xml = xml, Attachments = attachments }; ebmsVerifier.Verify(); }
public As4Message Build() { var envelope = CreateSoapEnvelope(); envelope.Header.Messaging.UserMessage.PartyInfo.From.PartyId.Value = Sender.Code; envelope.Header.Messaging.UserMessage.PartyInfo.To.PartyId.Value = Receiver.Code; envelope.Header.Messaging.UserMessage.CollaborationInfo.Service.Value = UseCase; envelope.Header.Messaging.UserMessage.PayloadInfo = new List <PartInfo>(); if (Sed != null) { var sedPart = new PartInfo { Reference = $"cid:{Sed.ContentId}", PartProperties = new List <Property> { new Property { Name = "PartType", Value = "SED" }, new Property { Name = "MimeType", Value = Sed.ContentType } } }; if (Sed.IsCompressionRequired) { Sed.Stream = Compress(Sed.Stream); sedPart.PartProperties.Add(new Property { Name = "CompressionType", Value = "application/gzip" }); } envelope.Header.Messaging.UserMessage.PayloadInfo.Add(sedPart); } foreach (var attachment in Attachments) { if (attachment.IsCompressionRequired) { attachment.Stream = Compress(attachment.Stream); } var attachmentPart = new PartInfo { Reference = $"cid:{attachment.ContentId}", PartProperties = new List <Property> { new Property { Name = "PartType", Value = "Attachment" }, new Property { Name = "MimeType", Value = attachment.ContentType }, } }; if (attachment.IsCompressionRequired) { attachment.Stream = Compress(attachment.Stream); attachmentPart.PartProperties.Add(new Property { Name = "CompressionType", Value = "application/gzip" }); } envelope.Header.Messaging.UserMessage.PayloadInfo.Add(attachmentPart); } var message = new As4Message(); message.Set(envelope); message.Attachments.Add(Sed); Sed.Stream.Position = 0; var ebmsSigner = new EbmsSigner { Xml = message.SoapEnvelope, Certificate = Sender.Ebms, Uris = new [] { envelope.Header.Messaging.Id, envelope.Body.Id }, Attachments = message.Attachments }; ebmsSigner.Sign(); return(message); }