private static async Task <AS4Message> PullResponseWarning() { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(as4_pullrequest_warning))) { var serializer = new SoapEnvelopeSerializer(); return(await serializer.DeserializeAsync(stream, Constants.ContentTypes.Soap)); } }
private static async Task <AS4Message> GetAS4Message(string soapEnvelopeString) { var serializer = new SoapEnvelopeSerializer(); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(soapEnvelopeString))) { return(await serializer.DeserializeAsync(stream, "soap/xml")); } }
public async Task Predifined_BizTalk_Sample_Fails_To_Deserialize_Because_Of_Missing_Body() { using (var input = new MemoryStream(Encoding.UTF8.GetBytes(BizTalkUserMessage))) { var sut = new SoapEnvelopeSerializer(); await Assert.ThrowsAsync <ArgumentNullException>( () => sut.DeserializeAsync(input, Constants.ContentTypes.Soap)); } }
private static Task <AS4Message> SerializeDeserializeSoap(AS4Message msg) { var serializer = new SoapEnvelopeSerializer(); var memory = new MemoryStream(); serializer.Serialize(msg, memory); memory.Position = 0; return(serializer.DeserializeAsync(memory, msg.ContentType)); }
protected async Task <MessagingContext> DeserializeSignedMessage(string xml) { var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml)); var serializer = new SoapEnvelopeSerializer(); const string contentType = "multipart/related; boundary=\"=-dXYE+NJdacou7AbmYZgUPw==\"; type=\"application/soap+xml\"; charset=\"utf-8\""; AS4Message as4Message = await serializer.DeserializeAsync(memoryStream, contentType); return(new MessagingContext(as4Message, MessagingContextMode.Unknown)); }
protected XmlDocument SerializeSoapMessage(AS4Message message, MemoryStream soapStream) { ISerializer serializer = new SoapEnvelopeSerializer(); serializer.Serialize(message, soapStream); soapStream.Position = 0; var document = new XmlDocument(); document.Load(soapStream); return(document); }
private async Task CorrectHandlingOnSynchronouslyReceivedMultiHopReceipt( bool actAsIntermediaryMsh, string receivePModeId, OutStatus expectedOutStatus, Operation expectedSignalOperation) { // Arrange SendingProcessingMode pmode = CreateMultihopPMode(StubListenLocation); UserMessage simpleUserMessage = CreateMultihopUserMessage(receivePModeId, pmode); AS4Message as4Message = AS4Message.Create(simpleUserMessage, pmode); var signal = new ManualResetEvent(false); var serializer = new SoapEnvelopeSerializer(); StubHttpServer.StartServer( StubListenLocation, res => { res.StatusCode = 200; res.ContentType = Constants.ContentTypes.Soap; var receipt = Receipt.CreateFor( $"receipt-{Guid.NewGuid()}", as4Message.FirstUserMessage, userMessageSendViaMultiHop: true); serializer.Serialize(AS4Message.Create(receipt), res.OutputStream); }, signal); // Act PutMessageToSend(as4Message, pmode, actAsIntermediaryMsh); // Assert signal.WaitOne(); OutMessage sentMessage = await PollUntilPresent( () => _databaseSpy.GetOutMessageFor(m => m.EbmsMessageId == simpleUserMessage.MessageId), timeout : TimeSpan.FromSeconds(10)); Assert.Equal(expectedOutStatus, sentMessage.Status.ToEnum <OutStatus>()); InMessage receivedMessage = await PollUntilPresent( () => _databaseSpy.GetInMessageFor(m => m.EbmsRefToMessageId == simpleUserMessage.MessageId), timeout : TimeSpan.FromSeconds(10)); Assert.Equal(MessageType.Receipt, receivedMessage.EbmsMessageType); Assert.Equal(expectedSignalOperation, receivedMessage.Operation); }
public async Task DeserializeSoapEnvelopeWithoutMessagingHeaderThrowsInvalidMessageException() { const string xmlContent = @"<?xml version=""1.0""?><s12:Envelope xmlns:s12 = ""http://www.w3.org/2003/05/soap-envelope""><s12:Header/></s12:Envelope>"; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlContent))) { await Assert.ThrowsAsync <InvalidMessageException>( async() => { var s = new SoapEnvelopeSerializer(); await s.DeserializeAsync(stream, "application/xml"); }); } }
public async Task Then_MessageUnits_Appear_In_The_Same_Order_As_Serialized() { var serializer = new SoapEnvelopeSerializer(); using (var str = new MemoryStream( Encoding.UTF8.GetBytes( Properties.Resources.as4_soap_user_receipt_message))) { AS4Message actual = await serializer .DeserializeAsync(str, Constants.ContentTypes.Soap); Assert.IsType <Receipt>(actual.MessageUnits.First()); Assert.IsType <UserMessage>(actual.MessageUnits.ElementAt(1)); Assert.IsType <Receipt>(actual.MessageUnits.Last()); Assert.Equal( Enumerable.Range(1, 3), actual.MessageUnits.Select(m => int.Parse(m.MessageId))); } }
public void ThenMpcAttributeIsCorrectlySerialized() { var userMessage = new UserMessage("some-message-id", "the-specified-mpc"); var as4Message = AS4Message.Create(userMessage); using (var messageStream = new MemoryStream()) { var sut = new SoapEnvelopeSerializer(); // Act sut.Serialize(as4Message, messageStream); // Assert messageStream.Position = 0; var xmlDocument = new XmlDocument(); xmlDocument.Load(messageStream); var userMessageNode = xmlDocument.SelectSingleNode("//*[local-name()='UserMessage']"); Assert.NotNull(userMessageNode); Assert.Equal(userMessage.Mpc, userMessageNode.Attributes["mpc"].InnerText); } }
/// <summary> /// Creates message with a SOAP envelope. /// </summary> /// <param name="soapEnvelope">The SOAP envelope.</param> /// <param name="contentType">Type of the content.</param> /// <param name="securityHeader"></param> /// <param name="messagingHeader"></param> /// <param name="bodyElement"></param> ///<remarks>This method should only be used when creating an AS4 Message via deserialization.</remarks> /// <returns></returns> internal static async Task <AS4Message> CreateAsync( XmlDocument soapEnvelope, string contentType, SecurityHeader securityHeader, Xml.Messaging messagingHeader, Xml.Body1 bodyElement) { if (soapEnvelope == null) { throw new ArgumentNullException(nameof(soapEnvelope)); } if (String.IsNullOrWhiteSpace(contentType)) { throw new ArgumentException(@"ContentType must be defined.", nameof(contentType)); } if (securityHeader == null) { throw new ArgumentNullException(nameof(securityHeader)); } if (messagingHeader == null) { throw new ArgumentNullException(nameof(messagingHeader)); } if (bodyElement == null) { throw new ArgumentNullException(nameof(bodyElement)); } var result = new AS4Message { EnvelopeDocument = soapEnvelope, ContentType = contentType, SecurityHeader = securityHeader }; bool?IsMultihopAttributePresent() { const string messagingXPath = "/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='Messaging']"; if (result.EnvelopeDocument?.SelectSingleNode(messagingXPath) is XmlElement messagingNode) { string role = messagingNode.GetAttribute("role", Constants.Namespaces.Soap12); return(!string.IsNullOrWhiteSpace(role) && role.Equals(Constants.Namespaces.EbmsNextMsh)); } return(null); } result.__hasMultiHopAttribute = IsMultihopAttributePresent(); string bodySecurityId = null; if (bodyElement.AnyAttr != null) { bodySecurityId = bodyElement.AnyAttr.FirstOrDefault(a => a.LocalName == "Id")?.Value; } result.SigningId = new SigningId(messagingHeader.SecurityId, bodySecurityId); result._messageUnits.AddRange( await SoapEnvelopeSerializer.GetMessageUnitsFromMessagingHeader(soapEnvelope, messagingHeader)); return(result); }