Пример #1
0
        /// <summary>
        /// Gets the content of an WsMtomBodyPart.
        /// </summary>
        /// <param name="contentID">A string containing a unique content identifier.</param>
        /// <param name="bodyParts">A WsMtomBodyParts collection.</param>
        /// <returns>A byte array containing the body part content.</returns>
        public byte[] GetBodyPartContent(string contentID, WsMtomBodyParts bodyParts)
        {
            WsMtomBodyPart bodyPart = null;

            // XmlReader will convert ':' and '/' to their respective HEX values (%3A, %2F)
            // for attributes values.  So we need to switch them back in order for the compare to work
            // We may want to change the XML parser to handle this in a more generic way
            int idx = contentID.IndexOf("%");

            while (idx != -1)
            {
                if (contentID[idx + 1] == '3' && contentID[idx + 2] == 'A')
                {
                    contentID = contentID.Substring(0, idx) + ":" + contentID.Substring(idx + 3);
                }
                else if (contentID[idx + 1] == '2' && contentID[idx + 2] == 'F')
                {
                    contentID = contentID.Substring(0, idx) + "/" + contentID.Substring(idx + 3);
                }
                idx = contentID.IndexOf("%", idx);
            }

            if ((bodyPart = bodyParts["<" + contentID.Substring(4) + ">"]) != null)
            {
                return(bodyPart.Content.ToArray());
            }
            return(null);
        }
Пример #2
0
 /// <summary>
 /// Creates an instance of a DataContractSerilizer used to serialize and deserialize xml to
 /// and from a type.
 /// </summary>
 /// <param name="rootName">A string containing the name of the root element of a type.</param>
 /// <param name="rootNamespace">A string containing the namespace of the root element of a type.</param>
 /// <param name="localNamespace">A string containing the namespace of the child element of a type.</param>
 protected DataContractSerializer(string rootName, string rootNamespace, string localNamespace)
 {
     _attributesFound    = new ArrayList();
     BodyParts           = new WsMtomBodyParts();
     _rootName           = rootName;
     _rootNamespace      = rootNamespace;
     _localNamespace     = localNamespace;
     _CompressByteArrays = true;
 }
Пример #3
0
        /// <summary>
        /// Creates an instance of a WsResponseMessage inintilized from an mtom body parts object.
        /// </summary>
        /// <param name="bodyParts">An mtom body parts object.</param>
        /// <exception cref="ArgumentNullException">If the bodyParts parameter is null.</exception>
        /// <remarks>
        /// This contructor processes an mtom body parts collection and uilds an mtom message.
        /// It also sets the Boundary and StartContenID properties from the body parts object.
        /// </remarks>
        public WsMessage(WsMtomBodyParts bodyParts)
        {
            Debug.Assert(bodyParts != null);

            this.MessageType = WsMessageType.Mtom;

            this.Message   = new WsMtom().CreateMessage(bodyParts);
            this.BodyParts = bodyParts;
        }
Пример #4
0
        /// <summary>
        /// Stop tranport services and releases the managed resources used by this class.
        /// </summary>
        /// <param name="disposing">True to release managed resources</param>
        internal void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Stop the transport services
                m_httpServiceHost.Stop();
                m_udpSeviceHost.Stop();

                m_threadLock               = null;
                m_discoClient              = null;
                m_endpointAddress          = null;
                m_eventClient              = null;
                m_mexClient                = null;
                m_eventCallbacks           = null;
                m_transportAddress         = null;
                m_bodyParts                = null;
                m_discoServiceEndpoints    = null;
                m_callbackServiceEndpoints = null;
                m_udpSeviceHost            = null;
                m_httpServiceHost          = null;
            }
        }
Пример #5
0
        /// <summary>
        /// Send an Http request containing an mtom message to an endpoint and waits for a response.
        /// </summary>
        /// <param name="bodyParts">A reference to the WsMtomBodyParts collection used to generate a mime multipart message.</param>
        /// <param name="endpointAddress">A string containing the endpoint address of a service that will receive
        /// <param name="isOneway">True = don't wait for response, false means wait for a response.</param>
        /// <param name="isChuncked">If true true the message will be chunk encoded.</param>
        /// <returns>
        /// A DpwSoapResponse object containing a WsWsaHeader and an XmlReader or null if no response is received
        /// or parsing fails.
        /// </returns>
        public DpwsSoapResponse SendRequest(ref WsMtomBodyParts bodyParts, string endpointAddress, bool isOneWay, bool isChuncked)
        {
            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;
            WsMtom mtom = new WsMtom();

            byte[]    message  = mtom.CreateMessage(bodyParts);
            WsMessage response = SendRequest(message, endpointAddress, isOneWay, isChuncked, mtomParams);

            if (isOneWay)
            {
                return(null);
            }

            XmlReader   reader;
            WsWsaHeader header;

            try
            {
                reader    = WsSoapMessageParser.ParseSoapMessage(response.Message, out header);
                bodyParts = response.BodyParts;
            }
            catch
            {
                System.Ext.Console.Write("ParseSoapMessage failed.");
                return(null);
            }

            return(new DpwsSoapResponse(header, reader));
        }
Пример #6
0
        /// <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);
        }