Exemplo n.º 1
0
        private object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall)
        {
            SoapClientMethod method          = message.Method;
            HttpWebResponse  httpWebResponse = response as HttpWebResponse;
            int num1 = httpWebResponse != null ? (int)httpWebResponse.StatusCode : -1;

            if (num1 >= 300 && num1 != 500 && num1 != 400)
            {
                throw new WebException(RequestResponseUtils.CreateResponseExceptionString((WebResponse)httpWebResponse, responseStream), (Exception)null, WebExceptionStatus.ProtocolError, (WebResponse)httpWebResponse);
            }
            message.Headers.Clear();
            message.SetStream(responseStream);
            message.InitExtensionStreamChain(message.initializedExtensions);
            message.SetStage(SoapMessageStage.BeforeDeserialize);
            message.ContentType     = response.ContentType;
            message.ContentEncoding = ((NameValueCollection)response.Headers)["Content-Encoding"];
            message.RunExtensions(message.initializedExtensions, false);
            if (method.oneWay && (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.InternalServerError))
            {
                return(new object[0]);
            }
            bool flag1 = ContentType.IsSoap(message.ContentType);

            if (!flag1 || flag1 && httpWebResponse != null && httpWebResponse.ContentLength == 0L)
            {
                if (num1 == 400)
                {
                    throw new WebException(RequestResponseUtils.CreateResponseExceptionString((WebResponse)httpWebResponse, responseStream), (Exception)null, WebExceptionStatus.ProtocolError, (WebResponse)httpWebResponse);
                }
                throw new InvalidOperationException(System.Web.Services.Res.GetString("WebResponseContent", (object)message.ContentType, (object)this.HttpContentType) + Environment.NewLine + RequestResponseUtils.CreateResponseExceptionString(response, responseStream));
            }
            else
            {
                if (message.Exception != null)
                {
                    throw message.Exception;
                }
                int       bufferSize       = asyncCall || httpWebResponse == null ? 512 : RequestResponseUtils.GetBufferSize((int)httpWebResponse.ContentLength);
                XmlReader readerForMessage = this.GetReaderForMessage(message, bufferSize);
                if (readerForMessage == null)
                {
                    throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullReaderForMessage"));
                }
                int    num2         = (int)readerForMessage.MoveToContent();
                int    depth        = readerForMessage.Depth;
                string encodingNs   = this.EncodingNs;
                string namespaceUri = readerForMessage.NamespaceURI;
                if (namespaceUri == null || namespaceUri.Length == 0)
                {
                    readerForMessage.ReadStartElement("Envelope");
                }
                else if (readerForMessage.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/")
                {
                    readerForMessage.ReadStartElement("Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
                }
                else if (readerForMessage.NamespaceURI == "http://www.w3.org/2003/05/soap-envelope")
                {
                    readerForMessage.ReadStartElement("Envelope", "http://www.w3.org/2003/05/soap-envelope");
                }
                else
                {
                    throw new SoapException(System.Web.Services.Res.GetString("WebInvalidEnvelopeNamespace", (object)namespaceUri, (object)this.EnvelopeNs), SoapException.VersionMismatchFaultCode);
                }
                int num3 = (int)readerForMessage.MoveToContent();
                new SoapHeaderHandling().ReadHeaders(readerForMessage, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, namespaceUri, method.use == SoapBindingUse.Encoded ? encodingNs : (string)null, false);
                int num4 = (int)readerForMessage.MoveToContent();
                readerForMessage.ReadStartElement("Body", namespaceUri);
                int num5 = (int)readerForMessage.MoveToContent();
                if (readerForMessage.IsStartElement("Fault", namespaceUri))
                {
                    message.Exception = this.ReadSoapException(readerForMessage);
                }
                else if (method.oneWay)
                {
                    readerForMessage.Skip();
                    message.SetParameterValues(new object[0]);
                }
                else
                {
                    TraceMethod caller = Tracing.On ? new TraceMethod((object)this, "ReadResponse", new object[0]) : (TraceMethod)null;
                    bool        flag2  = method.use == SoapBindingUse.Encoded;
                    if (Tracing.On)
                    {
                        Tracing.Enter(Tracing.TraceId("TraceReadResponse"), caller, new TraceMethod((object)method.returnSerializer, "Deserialize", new object[2]
                        {
                            (object)readerForMessage,
                            flag2 ? (object)encodingNs : (object)(string)null
                        }));
                    }
                    if (!flag2 && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On))
                    {
                        XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents();
                        message.SetParameterValues((object[])method.returnSerializer.Deserialize(readerForMessage, (string)null, events));
                    }
                    else
                    {
                        message.SetParameterValues((object[])method.returnSerializer.Deserialize(readerForMessage, flag2 ? encodingNs : (string)null));
                    }
                    if (Tracing.On)
                    {
                        Tracing.Exit(Tracing.TraceId("TraceReadResponse"), caller);
                    }
                }
                do
                {
                    ;
                }while (depth < readerForMessage.Depth && readerForMessage.Read());
                if (readerForMessage.NodeType == XmlNodeType.EndElement)
                {
                    readerForMessage.Read();
                }
                message.SetStage(SoapMessageStage.AfterDeserialize);
                message.RunExtensions(message.initializedExtensions, false);
                SoapHeaderHandling.SetHeaderMembers(message.Headers, (object)this, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, true);
                if (message.Exception != null)
                {
                    throw message.Exception;
                }
                else
                {
                    return(message.GetParameterValues());
                }
            }
        }
Exemplo n.º 2
0
 public new TRoot Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
 {
     return((TRoot)base.Deserialize(xmlReader, events));
 }
Exemplo n.º 3
0
 public new T Deserialize(XmlReader xmlReader, XmlDeserializationEvents events) => base.Deserialize(xmlReader, events) as T;
Exemplo n.º 4
0
        private object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall)
        {
            int bufferSize;
            SoapClientMethod method    = message.Method;
            HttpWebResponse  response2 = response as HttpWebResponse;
            int num = (response2 != null) ? ((int)response2.StatusCode) : -1;

            if (((num >= 300) && (num != 500)) && (num != 400))
            {
                throw new WebException(RequestResponseUtils.CreateResponseExceptionString(response2, responseStream), null, WebExceptionStatus.ProtocolError, response2);
            }
            message.Headers.Clear();
            message.SetStream(responseStream);
            message.InitExtensionStreamChain(message.initializedExtensions);
            message.SetStage(SoapMessageStage.BeforeDeserialize);
            message.ContentType     = response.ContentType;
            message.ContentEncoding = response.Headers["Content-Encoding"];
            message.RunExtensions(message.initializedExtensions, false);
            if (method.oneWay && ((response2 == null) || (response2.StatusCode != HttpStatusCode.InternalServerError)))
            {
                return(new object[0]);
            }
            bool flag = ContentType.IsSoap(message.ContentType);

            if (!flag || ((flag && (response2 != null)) && (response2.ContentLength == 0L)))
            {
                if (num == 400)
                {
                    throw new WebException(RequestResponseUtils.CreateResponseExceptionString(response2, responseStream), null, WebExceptionStatus.ProtocolError, response2);
                }
                throw new InvalidOperationException(System.Web.Services.Res.GetString("WebResponseContent", new object[] { message.ContentType, this.HttpContentType }) + Environment.NewLine + RequestResponseUtils.CreateResponseExceptionString(response, responseStream));
            }
            if (message.Exception != null)
            {
                throw message.Exception;
            }
            if (asyncCall || (response2 == null))
            {
                bufferSize = 0x200;
            }
            else
            {
                bufferSize = RequestResponseUtils.GetBufferSize((int)response2.ContentLength);
            }
            XmlReader readerForMessage = this.GetReaderForMessage(message, bufferSize);

            if (readerForMessage == null)
            {
                throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullReaderForMessage"));
            }
            readerForMessage.MoveToContent();
            int    depth        = readerForMessage.Depth;
            string encodingNs   = this.EncodingNs;
            string namespaceURI = readerForMessage.NamespaceURI;

            if ((namespaceURI == null) || (namespaceURI.Length == 0))
            {
                readerForMessage.ReadStartElement("Envelope");
            }
            else if (readerForMessage.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/")
            {
                readerForMessage.ReadStartElement("Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
            }
            else
            {
                if (readerForMessage.NamespaceURI != "http://www.w3.org/2003/05/soap-envelope")
                {
                    throw new SoapException(System.Web.Services.Res.GetString("WebInvalidEnvelopeNamespace", new object[] { namespaceURI, this.EnvelopeNs }), SoapException.VersionMismatchFaultCode);
                }
                readerForMessage.ReadStartElement("Envelope", "http://www.w3.org/2003/05/soap-envelope");
            }
            readerForMessage.MoveToContent();
            new SoapHeaderHandling().ReadHeaders(readerForMessage, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Fault | SoapHeaderDirection.Out, namespaceURI, (method.use == SoapBindingUse.Encoded) ? encodingNs : null, false);
            readerForMessage.MoveToContent();
            readerForMessage.ReadStartElement("Body", namespaceURI);
            readerForMessage.MoveToContent();
            if (readerForMessage.IsStartElement("Fault", namespaceURI))
            {
                message.Exception = this.ReadSoapException(readerForMessage);
            }
            else if (method.oneWay)
            {
                readerForMessage.Skip();
                message.SetParameterValues(new object[0]);
            }
            else
            {
                TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadResponse", new object[0]) : null;
                bool        flag2  = method.use == SoapBindingUse.Encoded;
                if (Tracing.On)
                {
                    Tracing.Enter(Tracing.TraceId("TraceReadResponse"), caller, new TraceMethod(method.returnSerializer, "Deserialize", new object[] { readerForMessage, flag2 ? encodingNs : null }));
                }
                if (!flag2 && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On))
                {
                    XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents();
                    message.SetParameterValues((object[])method.returnSerializer.Deserialize(readerForMessage, null, events));
                }
                else
                {
                    message.SetParameterValues((object[])method.returnSerializer.Deserialize(readerForMessage, flag2 ? encodingNs : null));
                }
                if (Tracing.On)
                {
                    Tracing.Exit(Tracing.TraceId("TraceReadResponse"), caller);
                }
            }
            while ((depth < readerForMessage.Depth) && readerForMessage.Read())
            {
            }
            if (readerForMessage.NodeType == XmlNodeType.EndElement)
            {
                readerForMessage.Read();
            }
            message.SetStage(SoapMessageStage.AfterDeserialize);
            message.RunExtensions(message.initializedExtensions, false);
            SoapHeaderHandling.SetHeaderMembers(message.Headers, this, method.outHeaderMappings, SoapHeaderDirection.Fault | SoapHeaderDirection.Out, true);
            if (message.Exception != null)
            {
                throw message.Exception;
            }
            return(message.GetParameterValues());
        }
 public object Deserialize(System.Xml.XmlReader xmlReader, XmlDeserializationEvents events)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Deserializes an XML document contained by the specified <see cref="T:System.Xml.XmlReader"/> and allows the overriding of events that occur during deserialization.
 /// </summary>
 /// <returns>
 ///     The <see cref="T:System.Object"/> being deserialized.
 /// </returns>
 /// <param name="xmlReader">The <see cref="T:System.Xml.XmlReader"/> that contains the document to deserialize.</param><param name="events">An instance of the <see cref="T:System.Xml.Serialization.XmlDeserializationEvents"/> class. </param>
 public object Deserialize(XmlReader xmlReader,
                           XmlDeserializationEvents events)
 {
     return(this.XmlSerializerInstance.Deserialize(xmlReader, null, events));
 }
Exemplo n.º 7
0
 public static T Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
 {
     return((T)Serializer(typeof(T)).Deserialize(xmlReader, events));
 }
        object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall)
        {
            SoapClientMethod method = message.Method;

            //


            HttpWebResponse httpResponse = response as HttpWebResponse;
            int             statusCode   = httpResponse != null ? (int)httpResponse.StatusCode : -1;

            if (statusCode >= 300 && statusCode != 500 && statusCode != 400)
            {
                throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null,
                                       WebExceptionStatus.ProtocolError, httpResponse);
            }

            message.Headers.Clear();
            message.SetStream(responseStream);
            message.InitExtensionStreamChain(message.initializedExtensions);

            message.SetStage(SoapMessageStage.BeforeDeserialize);
            message.ContentType     = response.ContentType;
            message.ContentEncoding = response.Headers[ContentType.ContentEncoding];
            message.RunExtensions(message.initializedExtensions, false);

            if (method.oneWay && (httpResponse == null || (int)httpResponse.StatusCode != 500))
            {
                return(new object[0]);
            }

            // this statusCode check is just so we don't repeat the contentType check we did above
            bool isSoap = ContentType.IsSoap(message.ContentType);

            if (!isSoap || (isSoap && (httpResponse != null) && (httpResponse.ContentLength == 0)))
            {
                // special-case 400 since we exempted it above on the off-chance it might be a soap 1.2 sender fault.
                // based on the content-type, it looks like it's probably just a regular old 400
                if (statusCode == 400)
                {
                    throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null,
                                           WebExceptionStatus.ProtocolError, httpResponse);
                }
                else
                {
                    throw new InvalidOperationException(Res.GetString(Res.WebResponseContent, message.ContentType, HttpContentType) +
                                                        Environment.NewLine +
                                                        RequestResponseUtils.CreateResponseExceptionString(response, responseStream));
                }
            }
            if (message.Exception != null)
            {
                throw message.Exception;
            }

            // perf fix: changed buffer size passed to StreamReader
            int bufferSize;

            if (asyncCall || httpResponse == null)
            {
                bufferSize = 512;
            }
            else
            {
                bufferSize = RequestResponseUtils.GetBufferSize((int)httpResponse.ContentLength);
            }
            XmlReader reader = GetReaderForMessage(message, bufferSize);

            if (reader == null)
            {
                throw new InvalidOperationException(Res.GetString(Res.WebNullReaderForMessage));
            }

            reader.MoveToContent();
            int depth = reader.Depth;

            // should be able to handle no ns, soap 1.1 ns, or soap 1.2 ns
            string encodingNs = EncodingNs;
            string envelopeNs = reader.NamespaceURI;

            if (envelopeNs == null || envelopeNs.Length == 0)
            {
                // ok to omit namespace -- assume correct version
                reader.ReadStartElement(Soap.Element.Envelope);
            }
            else if (reader.NamespaceURI == Soap.Namespace)
            {
                reader.ReadStartElement(Soap.Element.Envelope, Soap.Namespace);
            }
            else if (reader.NamespaceURI == Soap12.Namespace)
            {
                reader.ReadStartElement(Soap.Element.Envelope, Soap12.Namespace);
            }
            else
            {
                throw new SoapException(Res.GetString(Res.WebInvalidEnvelopeNamespace, envelopeNs, EnvelopeNs), SoapException.VersionMismatchFaultCode);
            }

            reader.MoveToContent();
            SoapHeaderHandling headerHandler = new SoapHeaderHandling();

            headerHandler.ReadHeaders(reader, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, envelopeNs, method.use == SoapBindingUse.Encoded ? encodingNs : null, false);
            reader.MoveToContent();
            reader.ReadStartElement(Soap.Element.Body, envelopeNs);
            reader.MoveToContent();
            if (reader.IsStartElement(Soap.Element.Fault, envelopeNs))
            {
                message.Exception = ReadSoapException(reader);
            }
            else
            {
                if (method.oneWay)
                {
                    reader.Skip();
                    message.SetParameterValues(new object[0]);
                }
                else
                {
                    TraceMethod caller        = Tracing.On ? new TraceMethod(this, "ReadResponse") : null;
                    bool        isEncodedSoap = method.use == SoapBindingUse.Encoded;
                    if (Tracing.On)
                    {
                        Tracing.Enter(Tracing.TraceId(Res.TraceReadResponse), caller, new TraceMethod(method.returnSerializer, "Deserialize", reader, isEncodedSoap ? encodingNs : null));
                    }

                    bool useDeserializationEvents = !isEncodedSoap && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On);
                    if (useDeserializationEvents)
                    {
                        XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents();
                        message.SetParameterValues((object[])method.returnSerializer.Deserialize(reader, null, events));
                    }
                    else
                    {
                        message.SetParameterValues((object[])method.returnSerializer.Deserialize(reader, isEncodedSoap ? encodingNs : null));
                    }

                    if (Tracing.On)
                    {
                        Tracing.Exit(Tracing.TraceId(Res.TraceReadResponse), caller);
                    }
                }
            }

            // Consume soap:Body and soap:Envelope closing tags
            while (depth < reader.Depth && reader.Read())
            {
                // Nothing, just read on
            }
            // consume end tag
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                reader.Read();
            }

            message.SetStage(SoapMessageStage.AfterDeserialize);
            message.RunExtensions(message.initializedExtensions, false);
            SoapHeaderHandling.SetHeaderMembers(message.Headers, this, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, true);

            if (message.Exception != null)
            {
                throw message.Exception;
            }
            return(message.GetParameterValues());
        }
Exemplo n.º 9
0
 public static T Load(XmlReader inputReader, string encodingStyle, XmlDeserializationEvents events)
 {
     return((T)serializer.Deserialize(inputReader, encodingStyle, events));
 }
Exemplo n.º 10
0
 public static T Load(XmlReader inputReader, XmlDeserializationEvents events)
 {
     return((T)serializer.Deserialize(inputReader, events));
 }
Exemplo n.º 11
0
        public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders)
        {
            string headerElementName = null;

            reader.MoveToContent();
            if (!reader.IsStartElement("Header", envelopeNS))
            {
                if ((checkRequiredHeaders && (mappings != null)) && (mappings.Length > 0))
                {
                    headerElementName = GetHeaderElementName(mappings[0].headerType);
                }
                return(headerElementName);
            }
            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return(headerElementName);
            }
            this.unknownHeaders      = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            this.currentThread       = Thread.CurrentThread.GetHashCode();
            this.envelopeNS          = envelopeNS;
            int depth = reader.Depth;

            reader.ReadStartElement();
            reader.MoveToContent();
            XmlDeserializationEvents events = new XmlDeserializationEvents {
                OnUnknownElement     = new XmlElementEventHandler(this.OnUnknownElement),
                OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject)
            };
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders", new object[0]) : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId("TraceReadHeaders"), caller, new TraceMethod(serializer, "Deserialize", new object[] { reader, encodingStyle }));
            }
            object[] objArray = (object[])serializer.Deserialize(reader, encodingStyle, events);
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId("TraceReadHeaders"), caller);
            }
            for (int i = 0; i < objArray.Length; i++)
            {
                if (objArray[i] != null)
                {
                    SoapHeader header = (SoapHeader)objArray[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
                else if (checkRequiredHeaders && (headerElementName == null))
                {
                    headerElementName = GetHeaderElementName(mappings[i].headerType);
                }
            }
            this.currentThread = 0;
            this.envelopeNS    = null;
            foreach (SoapHeader header2 in this.unreferencedHeaders)
            {
                headers.Add(header2);
            }
            this.unreferencedHeaders = null;
            foreach (SoapHeader header3 in this.unknownHeaders)
            {
                headers.Add(header3);
            }
            this.unknownHeaders = null;
            while ((depth < reader.Depth) && reader.Read())
            {
            }
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                reader.Read();
            }
            return(headerElementName);
        }
 public static T Deserialize <T>(this System.Xml.Serialization.XmlSerializer serializer, XmlReader reader,
                                 XmlDeserializationEvents events)
 => (T)serializer.Deserialize(reader, events);
 public static async Task <object> DeserializeAsync(this System.Xml.Serialization.XmlSerializer serializer,
                                                    XmlReader xmlReader,
                                                    XmlDeserializationEvents events)
 => await new Func <XmlReader, XmlDeserializationEvents, object>(serializer.Deserialize)
 .RunAsync(xmlReader, events);
Exemplo n.º 14
0
 public new TRoot Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
 {
     return((TRoot)base.Deserialize(xmlReader, encodingStyle, events));
 }
Exemplo n.º 15
0
 public static T Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
 {
     return((T)Serializer(typeof(T)).Deserialize(xmlReader, encodingStyle, events));
 }
Exemplo n.º 16
0
        // return first missing header name;
        public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders)
        {
            string missingHeader = null;

            reader.MoveToContent();
            if (!reader.IsStartElement(Soap.Element.Header, envelopeNS))
            {
                if (checkRequiredHeaders && mappings != null && mappings.Length > 0)
                {
                    missingHeader = GetHeaderElementName(mappings[0].headerType);
                }
                return(missingHeader);
            }
            if (reader.IsEmptyElement)
            {
                reader.Skip(); return(missingHeader);
            }

            this.unknownHeaders      = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            // thread hash code is used to differentiate between deserializations in event callbacks
            this.currentThread = Thread.CurrentThread.GetHashCode();
            this.envelopeNS    = envelopeNS;

            int depth = reader.Depth;

            reader.ReadStartElement();
            reader.MoveToContent();

            XmlDeserializationEvents events = new XmlDeserializationEvents();

            events.OnUnknownElement     = new XmlElementEventHandler(this.OnUnknownElement);
            events.OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject);

            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders") : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId(Res.TraceReadHeaders), caller, new TraceMethod(serializer, "Deserialize", reader, encodingStyle));
            }
            object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle, events);
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId(Res.TraceReadHeaders), caller);
            }
            for (int i = 0; i < headerValues.Length; i++)
            {
                if (headerValues[i] != null)
                {
                    SoapHeader header = (SoapHeader)headerValues[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
                else if (checkRequiredHeaders)
                {
                    // run time check for R2738 A MESSAGE MUST include all soapbind:headers specified on a wsdl:input or wsdl:output of a wsdl:operationwsdl:binding that describes it.
                    if (missingHeader == null)
                    {
                        missingHeader = GetHeaderElementName(mappings[i].headerType);
                    }
                }
            }
            this.currentThread = 0;
            this.envelopeNS    = null;

            foreach (SoapHeader header in this.unreferencedHeaders)
            {
                headers.Add(header);
            }
            this.unreferencedHeaders = null;

            foreach (SoapHeader header in this.unknownHeaders)
            {
                headers.Add(header);
            }
            this.unknownHeaders = null;

            // Consume soap:Body and soap:Envelope closing tags
            while (depth < reader.Depth && reader.Read())
            {
                // Nothing, just read on
            }
            // consume end tag
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                reader.Read();
            }

            return(missingHeader);
        }
 public object Deserialize(System.Xml.XmlReader xmlReader, XmlDeserializationEvents events)
 {
 }
Exemplo n.º 18
0
        internal override object[] ReadParameters()
        {
            object[] objArray2;
            this.message.InitExtensionStreamChain(this.message.otherExtensions);
            this.message.RunExtensions(this.message.otherExtensions, true);
            if (!ContentType.IsSoap(this.message.ContentType))
            {
                throw new SoapException(System.Web.Services.Res.GetString("WebRequestContent", new object[] { this.message.ContentType, this.helper.HttpContentType }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), new SoapFaultSubCode(Soap12FaultCodes.UnsupportedMediaTypeFaultCode));
            }
            XmlReader xmlReader = null;

            try
            {
                xmlReader = this.GetXmlReader();
                xmlReader.MoveToContent();
                this.SetHelper(SoapServerProtocolHelper.GetHelper(this, xmlReader.NamespaceURI));
            }
            catch (XmlException exception)
            {
                throw new SoapException(System.Web.Services.Res.GetString("WebRequestUnableToRead"), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), exception);
            }
            this.CheckHelperVersion();
            if ((this.version == SoapProtocolVersion.Soap11) && !ContentType.MatchesBase(this.message.ContentType, this.helper.HttpContentType))
            {
                throw new SoapException(System.Web.Services.Res.GetString("WebRequestContent", new object[] { this.message.ContentType, this.helper.HttpContentType }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), new SoapFaultSubCode(Soap12FaultCodes.UnsupportedMediaTypeFaultCode));
            }
            if (this.message.Exception != null)
            {
                throw this.message.Exception;
            }
            try
            {
                object[] objArray;
                if (!xmlReader.IsStartElement("Envelope", this.helper.EnvelopeNs))
                {
                    throw new InvalidOperationException(System.Web.Services.Res.GetString("WebMissingEnvelopeElement"));
                }
                if (xmlReader.IsEmptyElement)
                {
                    throw new InvalidOperationException(System.Web.Services.Res.GetString("WebMissingBodyElement"));
                }
                int depth = xmlReader.Depth;
                xmlReader.ReadStartElement("Envelope", this.helper.EnvelopeNs);
                xmlReader.MoveToContent();
                bool   checkRequiredHeaders = ((this.serverMethod.wsiClaims & WsiProfiles.BasicProfile1_1) != WsiProfiles.None) && (this.version != SoapProtocolVersion.Soap12);
                string str = new SoapHeaderHandling().ReadHeaders(xmlReader, this.serverMethod.inHeaderSerializer, this.message.Headers, this.serverMethod.inHeaderMappings, SoapHeaderDirection.In, this.helper.EnvelopeNs, (this.serverMethod.use == SoapBindingUse.Encoded) ? this.helper.EncodingNs : null, checkRequiredHeaders);
                if (str != null)
                {
                    throw new SoapHeaderException(System.Web.Services.Res.GetString("WebMissingHeader", new object[] { str }), new XmlQualifiedName("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/"));
                }
                if (!xmlReader.IsStartElement("Body", this.helper.EnvelopeNs))
                {
                    throw new InvalidOperationException(System.Web.Services.Res.GetString("WebMissingBodyElement"));
                }
                xmlReader.ReadStartElement("Body", this.helper.EnvelopeNs);
                xmlReader.MoveToContent();
                bool        flag2  = this.serverMethod.use == SoapBindingUse.Encoded;
                TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadParameters", new object[0]) : null;
                if (Tracing.On)
                {
                    Tracing.Enter(Tracing.TraceId("TraceReadRequest"), caller, new TraceMethod(this.serverMethod.parameterSerializer, "Deserialize", new object[] { xmlReader, (this.serverMethod.use == SoapBindingUse.Encoded) ? this.helper.EncodingNs : null }));
                }
                if (!flag2 && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On))
                {
                    XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents();
                    objArray = (object[])this.serverMethod.parameterSerializer.Deserialize(xmlReader, null, events);
                }
                else
                {
                    objArray = (object[])this.serverMethod.parameterSerializer.Deserialize(xmlReader, flag2 ? this.helper.EncodingNs : null);
                }
                if (Tracing.On)
                {
                    Tracing.Exit(Tracing.TraceId("TraceReadRequest"), caller);
                }
                while ((depth < xmlReader.Depth) && xmlReader.Read())
                {
                }
                if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    xmlReader.Read();
                }
                this.message.SetParameterValues(objArray);
                objArray2 = objArray;
            }
            catch (SoapException)
            {
                throw;
            }
            catch (Exception exception2)
            {
                if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException))
                {
                    throw;
                }
                throw new SoapException(System.Web.Services.Res.GetString("WebRequestUnableToRead"), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), exception2);
            }
            return(objArray2);
        }
 public object Deserialize(System.Xml.XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
 {
 }
 public object Deserialize(System.Xml.XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
 {
 }
Exemplo n.º 21
0
 public T Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
 {
     return((T)_serializer.Deserialize(xmlReader, events));
 }
Exemplo n.º 22
0
 /// <summary>
 ///     Deserializes the object using the data contained by the specified <see cref="T:System.Xml.XmlReader"/>.
 /// </summary>
 /// <returns>
 ///     The object being deserialized.
 /// </returns>
 /// <param name="xmlReader">An instance of the <see cref="T:System.Xml.XmlReader"/> class used to read the document.</param><param name="encodingStyle">The encoding used.</param><param name="events">An instance of the <see cref="T:System.Xml.Serialization.XmlDeserializationEvents"/> class. </param>
 public object Deserialize(XmlReader xmlReader,
                           string encodingStyle,
                           XmlDeserializationEvents events)
 {
     return(this.XmlSerializerInstance.Deserialize(xmlReader, encodingStyle, events));
 }
Exemplo n.º 23
0
 public T Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
 {
     return((T)_serializer.Deserialize(xmlReader, encodingStyle, events));
 }
Exemplo n.º 24
0
        public void EmployeeResponseWithUnknownTagsTest()
        {
            var employeeRet                 = @"
<EmployeeRet>
    <ListID>1111111-111111111</ListID>
    <EditSequence>1234567890</EditSequence>
    <Name>Daric Teske</Name>
    <IsActive>true</IsActive>
    <FirstName>Daric</FirstName>
    <LastName>Teske</LastName>
    <Phone>5555555555</Phone>
    <Email>[email protected]</Email>
    <EmployeePayrollInfo>
        <IsCoveredByQualifiedPensionPlan>false</IsCoveredByQualifiedPensionPlan>
        <PayPeriod>Weekly</PayPeriod>
        <PayScheduleRef>
            <ListID>80000001-1286898172</ListID>
            <FullName>Weekly</FullName>
        </PayScheduleRef>
        <Earnings>
            <PayrollItemWageRef>
                <ListID>80000000-0000000001</ListID>
                <FullName>Field</FullName>
            </PayrollItemWageRef>
            <Rate>15.00</Rate>
        </Earnings>
        <Earnings>
            <PayrollItemWageRef>
                <ListID>80000000-0000000002</ListID>
                <FullName>Field Overtime</FullName>
            </PayrollItemWageRef>
            <Rate>25.00</Rate>
        </Earnings>
        <Earnings>
            <PayrollItemWageRef>
                <ListID>80000000-0000000003</ListID>
                <FullName>Field Double Time</FullName>
            </PayrollItemWageRef>
            <Rate>50.00</Rate>
        </Earnings>
        <Earnings>
            <PayrollItemWageRef>
                <ListID>80000000-0000000004</ListID>
                <FullName>Field Holiday</FullName>
            </PayrollItemWageRef>
            <Rate>30.00</Rate>
        </Earnings>
        <UseTimeDataToCreatePaychecks>UseTimeData</UseTimeDataToCreatePaychecks>
        <SickHours>
            <HoursAvailable>PT0H15M0S</HoursAvailable>
            <AccrualPeriod>EveryPaycheck</AccrualPeriod>
            <HoursAccrued>PT0H55M0S</HoursAccrued>
            <MaximumHours>PT48H0M0S</MaximumHours>
            <IsResettingHoursEachNewYear>false</IsResettingHoursEachNewYear>
            <HoursUsed>PT0H0M0S</HoursUsed>
            <YearBeginsDate>2020-01-01</YearBeginsDate>
            <AccrualStartDate>2000-01-01</AccrualStartDate>
        </SickHours>
        <VacationHours>
            <HoursAvailable>PT0H0M0S</HoursAvailable>
            <AccrualPeriod>EveryPaycheck</AccrualPeriod>
            <HoursAccrued>PT0H0M0S</HoursAccrued>
            <MaximumHours>PT0H0M0S</MaximumHours>
            <IsResettingHoursEachNewYear>false</IsResettingHoursEachNewYear>
            <HoursUsed>PT0H0M0S</HoursUsed>
            <YearBeginsDate>2020-01-01</YearBeginsDate>
            <AccrualStartDate>2000-01-01</AccrualStartDate>
        </VacationHours>
        <EmployeeTaxInfo>
            <StateLived>NE</StateLived>
            <StateWorked>NE</StateWorked>
            <IsStandardTaxationRequired>true</IsStandardTaxationRequired>
            <EmployeeTax>
                <IsSubjectToTax>true</IsSubjectToTax>
                <PayrollItemTaxRef>
                    <ListID>D0000-863012697</ListID>
                    <FullName>Federal Withholding</FullName>
                </PayrollItemTaxRef>
                <TaxInfo>
                    <TaxInfoCategory>ALLOWANCES</TaxInfoCategory>
                    <TaxInfoValue>1</TaxInfoValue>
                </TaxInfo>
                <TaxInfo>
                    <TaxInfoCategory>EXTRA_WITHHOLDING</TaxInfoCategory>
                    <TaxInfoValue>0.00</TaxInfoValue>
                </TaxInfo>
                <TaxInfo>
                    <TaxInfoCategory>FILING_STATUS</TaxInfoCategory>
                    <TaxInfoValue>256</TaxInfoValue>
                </TaxInfo>
            </EmployeeTax>
        </EmployeeTaxInfo>
        <EmployeeDirectDepositAccount>
            <BankName>Fake Bank</BankName>
            <RoutingNumber>111111111</RoutingNumber>
            <AccountNumber>111111111111</AccountNumber>
            <BankAccountType>Checking</BankAccountType>
        </EmployeeDirectDepositAccount>
    </EmployeePayrollInfo>
</EmployeeRet>";
            var response                    = new QbXmlResponse();
            var onUnknownElementCalled      = 0;
            XmlDeserializationEvents events = new XmlDeserializationEvents();

            events.OnUnknownElement += (object sender, XmlElementEventArgs e) =>
            {
                onUnknownElementCalled++;
                if (e.Element.Name == nameof(EmployeePayrollInfo.UseTimeDataToCreatePaychecks) && Enum.TryParse(typeof(UseTimeDataToCreatePaychecks), e.Element.InnerText, out object useTimeData))
                {
                    var employeePayrollInfo = (EmployeePayrollInfo)e.ObjectBeingDeserialized;
                    employeePayrollInfo.UseTimeDataToCreatePaychecksSpecified = true;
                    employeePayrollInfo.UseTimeDataToCreatePaychecks          = (UseTimeDataToCreatePaychecks)useTimeData;
                }
            };
            var rs = response.GetSingleItemFromResponse <EmployeeQueryRsType>(QuickBooksTestHelper.CreateQbXmlWithEnvelope(employeeRet, "EmployeeQueryRs"), events);

            var employees = rs.EmployeeRet;
            var employee  = employees[0];

            Assert.AreEqual(1, employees.Length);
            Assert.AreEqual("1111111-111111111", employee.ListID);

            // Custom event handler was called at least once
            Assert.GreaterOrEqual(onUnknownElementCalled, 1);

            // Custom event handler updated a known property captured by the OnUnknownElement event
            Assert.IsTrue(employee.EmployeePayrollInfo.UseTimeDataToCreatePaychecksSpecified);
            Assert.AreEqual(UseTimeDataToCreatePaychecks.UseTimeData, employee.EmployeePayrollInfo.UseTimeDataToCreatePaychecks);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Deserializes the XML data in the given XML reader to an object.
        /// </summary>
        /// <typeparam name="TEntity">Type represented by the XML document.</typeparam>
        /// <param name="xmlReader">XML reader of the data representing the object instance.</param>
        /// <param name="encodingStyle">Encoding style of the data in the XML reader.</param>
        /// <param name="events">An instance of the System.Xml.Serialization.XmlDeserializationEvents class.</param>
        /// <returns>Instance of the object in the XML reader.</returns>
        public TEntity Deserialize <TEntity>(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
            where TEntity : class
        {
            var serializer = this.GetSerializer(typeof(TEntity));
            var response   = serializer.Deserialize(xmlReader, encodingStyle, events);

            return(response as TEntity);
        }