コード例 #1
0
        public override object ReadObject(XmlReader reader)
        {
            NestedClass NestedClassField = null;

            if (IsParentStartElement(reader, false, true))
            {
                NestedClassField = new NestedClass();
                reader.Read();
                MtomDataDataContractSerializer MTDataDCS = new MtomDataDataContractSerializer("MTData", "http://schemas.datacontract.org/2004/07/WcfMtomService", "http://schemas.datacontract.org/2004/07/WcfMtomService");
                MTDataDCS.BodyParts     = this.BodyParts;
                NestedClassField.MTData = ((MtomData)(MTDataDCS.ReadObject(reader)));
                if (IsChildStartElement(reader, "MyData", true, false))
                {
                    reader.Read();
                    if (IsAttribute(reader, "href"))
                    {
                        string contentID;
                        contentID = reader.Value;
                        reader.MoveToElement();
                        reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include");
                        reader.ReadEndElement();
                        NestedClassField.MyData = GetBodyPartContent(contentID, BodyParts);
                    }
                    else
                    {
                        NestedClassField.MyData = ConvertBase64.FromBase64String(reader.ReadString());
                        reader.ReadEndElement();
                    }
                }
                reader.ReadEndElement();
            }
            return(NestedClassField);
        }
コード例 #2
0
        public override object ReadObject(XmlReader reader)
        {
            MtomData MtomDataField = null;

            if (IsParentStartElement(reader, false, true))
            {
                MtomDataField = new MtomData();
                reader.Read();
                if (IsChildStartElement(reader, "Data", true, false))
                {
                    reader.Read();
                    if (IsAttribute(reader, "href"))
                    {
                        string contentID;
                        contentID = reader.Value;
                        reader.MoveToElement();
                        reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include");
                        reader.ReadEndElement();
                        MtomDataField.Data = GetBodyPartContent(contentID, BodyParts);
                    }
                    else
                    {
                        MtomDataField.Data = ConvertBase64.FromBase64String(reader.ReadString());
                        reader.ReadEndElement();
                    }
                }
                reader.ReadEndElement();
            }
            return(MtomDataField);
        }
コード例 #3
0
        public override object ReadObject(XmlReader reader)
        {
            OneWayAttachmentRequest OneWayAttachmentRequestField = null;

            if (IsParentStartElement(reader, false, true))
            {
                OneWayAttachmentRequestField         = new OneWayAttachmentRequest();
                OneWayAttachmentRequestField.AnyAttr = ReadAnyAttribute(reader);
                reader.Read();
                if (IsChildStartElement(reader, "Param", true, true))
                {
                    reader.Read();
                    if (IsAttribute(reader, "href"))
                    {
                        string contentID;
                        contentID = reader.Value;
                        reader.MoveToElement();
                        reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include");
                        reader.ReadEndElement();
                        OneWayAttachmentRequestField.Param = GetBodyPartContent(contentID, BodyParts);
                    }
                    else
                    {
                        OneWayAttachmentRequestField.Param = ConvertBase64.FromBase64String(reader.ReadString());
                        reader.ReadEndElement();
                    }
                }
                OneWayAttachmentRequestField.Any = ReadAnyElement(reader, false);
                reader.ReadEndElement();
            }
            return(OneWayAttachmentRequestField);
        }
コード例 #4
0
        /// <summary>
        /// Parses request from client.
        /// Fills
        /// - HTTP Verb.
        /// - HTTP version.
        /// - Content Length.
        /// - Fills generic value name pair in WEB header collection.
        /// </summary>
        internal void ParseHTTPRequest()
        {
            // This is the request line.
            m_RequestString = m_clientStream.Read_HTTP_Line(HttpWebRequest.maxHTTPLineLength).Trim();

            // Split request line into 3 strings - VERB, URL and HTTP version.
            char[]   delimiter  = { ' ' };
            string[] requestStr = m_RequestString.Split(delimiter);
            // requestStr should consist of 3 parts.
            if (requestStr.Length < 3)
            {
                throw new ProtocolViolationException("Invalid HTTP request String: " + m_RequestString);
            }

            // We have at least 3 strings. Fills the proper fields
            m_requestVerb = requestStr[0];
            m_rawURL      = requestStr[1];

            // Process third string. It should be either http/1.1 or http/1.0
            string httpVerLowerCase = requestStr[2].ToLower();

            if (httpVerLowerCase.Equals("http/1.1"))
            {
                m_requestHttpVer = HttpVersion.Version11;
            }
            else if (httpVerLowerCase.Equals("http/1.0"))
            {
                m_requestHttpVer = HttpVersion.Version10;
            }
            else
            {
                throw new ProtocolViolationException("Unsupported HTTP version: " + requestStr[2]);
            }

            // Now it is list of HTTP headers:
            string line;
            int    headersLen = m_maxResponseHeadersLen;

            while ((line = m_clientStream.Read_HTTP_Header(HttpWebRequest.maxHTTPLineLength)).Length > 0)
            {
                // line.Length is used for the header. Substruct it.
                headersLen -= line.Length;
                // If total length used for header is exceeded, we break

                if (headersLen < 0)
                {
                    throw new ProtocolViolationException("Http Headers exceeding: " + m_maxResponseHeadersLen);
                }

                int sepIdx = line.IndexOf(':');
                if (sepIdx == -1)
                {
                    throw new ProtocolViolationException("Invalid HTTP Header: " + line);
                }

                string headerName          = line.Substring(0, sepIdx).Trim();
                string headerValue         = line.Substring(sepIdx + 1).Trim();
                string matchableHeaderName = headerName.ToLower();
                // Adds new header to collection.
                m_httpRequestHeaders.AddInternal(headerName, headerValue);

                // Now we check the value - name pair. For some of them we need to initilize member variables.
                headerName = headerName.ToLower();
                // If it is connection header
                if (headerName == "connection")
                {
                    // If value is "Keep-Alive" ( lower case now ), set m_KeepAlive to true;
                    headerValue = headerValue.ToLower();
                    m_KeepAlive = headerValue == "keep-alive";
                }

                // If user supplied user name and password - parse it and store in m_NetworkCredentials
                if (headerName == "authorization")
                {
                    int    sepSpace = headerValue.IndexOf(' ');
                    string authType = headerValue.Substring(0, sepSpace);
                    if (authType.ToLower() == "basic")
                    {
                        string authInfo = headerValue.Substring(sepSpace + 1);
                        // authInfo is base64 encoded username and password.
                        byte[] authInfoDecoded = ConvertBase64.FromBase64String(authInfo);
                        char[] authInfoDecChar = System.Text.Encoding.UTF8.GetChars(authInfoDecoded);
                        string strAuthInfo     = new string(authInfoDecChar);
                        // The strAuthInfo comes in format username:password. Parse it.
                        int sepColon = strAuthInfo.IndexOf(':');
                        if (sepColon != -1)
                        {
                            m_NetworkCredentials = new NetworkCredential(strAuthInfo.Substring(0, sepColon), strAuthInfo.Substring(sepColon + 1));
                        }
                    }
                }
            }

            // Http headers were processed. Now we search for content length.
            string strContentLen = m_httpRequestHeaders[HttpKnownHeaderNames.ContentLength];

            if (strContentLen != null)
            {
                try
                {
                    m_contentLength = Convert.ToInt32(strContentLen);
                }
                catch (Exception)
                {
                    throw new ProtocolViolationException("Invalid content length in request: " + strContentLen);
                }
            }
        }