Exemplo n.º 1
0
        /// <summary>
        /// Helper method used to build a Dpws compliant soap response message.
        /// </summary>
        /// <param name="header">A valid response header object.</param>
        /// <param name="Dcs">A data contract serializer used to serialize the response body.</param>
        /// <param name="bodyContent">A object containing the data to serialize.</param>
        /// <returns>A byte array containing the soap reponse message.</returns>
        public static byte[] BuildSoapMessage(WsWsaHeader header, Ws.Services.Serialization.DataContractSerializer Dcs, object bodyContent)
        {
            lock (m_ThreadLock)
            {
                // Build response message
                MemoryStream soapStream;
                soapStream = new MemoryStream();
                XmlWriter xmlWriter;
                xmlWriter = XmlWriter.Create(soapStream);

                // Write start message up to body element content
                WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.Wsdp, null, header, null);

                // Serialize the body element
                if (bodyContent != null)
                {
                    Dcs.WriteObject(xmlWriter, bodyContent);
                }

                WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter);

                // Flush writer and build return array
                xmlWriter.Flush();
                byte[] soapBuffer = soapStream.ToArray();
                xmlWriter.Close();

                // Return soap message
                return soapBuffer;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Helper method used by a hosted service to generate an event messages body elements.
        /// </summary>
        /// <param name="header">A valid response header object.</param>
        /// <param name="Dcs">A data contract serializer used to serialize the response body.</param>
        /// <param name="bodyContent">A object containing the data to serialize.</param>
        /// <returns>A byte array containg the serialized body elements of event message.</returns>
        public static byte[] BuildEventBody(WsWsaHeader header, Ws.Services.Serialization.DataContractSerializer Dcs, object bodyContent)
        {
            // Create an XmlWriter
            MemoryStream soapStream;
            soapStream = new MemoryStream();
            XmlWriter xmlWriter = XmlWriter.Create(soapStream);

            // Create Xml body element
            Dcs.WriteObject(xmlWriter, bodyContent);

            // Flush writer and build message buffer
            xmlWriter.Flush();
            byte[] soapBuffer = soapStream.ToArray();
            xmlWriter.Close();

            // return xml message buffer
            return soapBuffer;
        }