/// <summary> /// Processes a message /// </summary> /// <param name="msg">The message being processed.</param> /// <param name="ctx">The context associated with the message.</param> /// <returns>The handling status for this operation.</returns> protected override ChainResult OnProcessOutputMessage(ref WsMessage msg, BindingContext ctx) { byte[] data = null; // if the body is a byte[] then it is already serialized (UDP stuff) if (msg == null || (msg.Body != null && msg.Body is byte[])) { return(ChainResult.Continue); } // Build response message using (XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create()) { WsSoapMessageWriter smw = new WsSoapMessageWriter(ctx.Version); // Write start message up to body element content smw.WriteSoapMessageStart(xmlWriter, msg, ctx.Version.IncludeSoapHeaders); if (msg.Body != null && msg.Serializer != null) { DataContractSerializer ser = (DataContractSerializer)msg.Serializer; // Serialize the body element ser.WriteObject(xmlWriter, msg.Body); if (ser.BodyParts != null && ser.BodyParts.Count > 0) { msg.BodyParts = ser.BodyParts; } } // Write end message smw.WriteSoapMessageEnd(xmlWriter); data = xmlWriter.ToArray(); } WsMtomBodyParts bodyParts = msg.BodyParts; if (bodyParts != null) { DataContractSerializer reqDcs = (DataContractSerializer)msg.Serializer; bodyParts.Start = "<soap@soap>"; bodyParts.AddStart(reqDcs.CreateNewBodyPart(data, bodyParts.Start)); if (reqDcs.BodyParts.Count > 0) { bodyParts.Add(reqDcs.BodyParts[0]); } WsMtomParams mtomParams = new WsMtomParams(); if (bodyParts.Boundary == null) { bodyParts.Boundary = Guid.NewGuid().ToString() + '-' + Guid.NewGuid().ToString().Substring(0, 33); } mtomParams.start = bodyParts.Start; mtomParams.boundary = bodyParts.Boundary; msg.MtomPropeties = mtomParams; WsMtom mtom = new WsMtom(); data = mtom.CreateMessage(bodyParts); } msg.Body = data; return(ChainResult.Continue); }