Example #1
0
        private void DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, object[] parameters)
        {
            if (parts.Length != parameters.Length)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new ArgumentException(SR.Format(SR.SFxParameterCountMismatch, "parts", parts.Length, "parameters", parameters.Length), "parameters"));
            }

            int nextPartIndex = 0;

            while (reader.IsStartElement())
            {
                for (int i = nextPartIndex; i < parts.Length; i++)
                {
                    PartInfo part = parts[i];
                    if (IsPartElement(reader, part))
                    {
                        parameters[part.Description.Index] = DeserializeParameter(reader, parts[i]);
                        nextPartIndex = i + 1;
                    }
                    else
                    {
                        parameters[part.Description.Index] = null;
                    }
                }

                if (reader.IsStartElement())
                {
                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
        }
        private void DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, object[] parameters, bool isRequest)
        {
            int nextPartIndex = 0;

            while (reader.IsStartElement())
            {
                for (int i = nextPartIndex; i < parts.Length; i++)
                {
                    PartInfo part = parts[i];
                    if (part.Serializer.IsStartObject(reader))
                    {
                        object parameterValue = DeserializeParameter(reader, part, isRequest);
                        parameters[part.Description.Index] = parameterValue;
                        nextPartIndex = i + 1;
                    }
                    else
                    {
                        parameters[part.Description.Index] = null;
                    }
                }

                if (reader.IsStartElement())
                {
                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
        }
Example #3
0
        private void DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, object[] parameters)
        {
            if (parts.Length != parameters.Length)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("SFxParameterCountMismatch", new object[] { "parts", parts.Length, "parameters", parameters.Length }), "parameters"));
            }
            int num = 0;

            while (reader.IsStartElement())
            {
                for (int i = num; i < parts.Length; i++)
                {
                    PartInfo part = parts[i];
                    if (this.IsPartElement(reader, part))
                    {
                        parameters[part.Description.Index] = this.DeserializeParameter(reader, parts[i]);
                        num = i + 1;
                    }
                    else
                    {
                        parameters[part.Description.Index] = null;
                    }
                }
                if (reader.IsStartElement())
                {
                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
        }
Example #4
0
        protected override object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            MessageInfo requestMessageInfo;
            PartInfo    info2;

            if (reader == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
            }
            if (parameters == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parameters"));
            }
            if (isRequest)
            {
                requestMessageInfo = this.requestMessageInfo;
            }
            else
            {
                requestMessageInfo = this.replyMessageInfo;
            }
            if (requestMessageInfo.WrapperName != null)
            {
                if (!reader.IsStartElement(requestMessageInfo.WrapperName, requestMessageInfo.WrapperNamespace))
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(System.ServiceModel.SR.GetString("SFxInvalidMessageBody", new object[] { requestMessageInfo.WrapperName, requestMessageInfo.WrapperNamespace, reader.NodeType, reader.Name, reader.NamespaceURI })));
                }
                bool isEmptyElement = reader.IsEmptyElement;
                reader.Read();
                if (isEmptyElement)
                {
                    return(null);
                }
            }
            object obj2 = null;

            if (requestMessageInfo.ReturnPart == null)
            {
                goto Label_010E;
            }
Label_00DC:
            info2 = requestMessageInfo.ReturnPart;
            if (info2.Serializer.IsStartObject(reader))
            {
                obj2 = this.DeserializeParameter(reader, info2, isRequest);
            }
            else if (reader.IsStartElement())
            {
                OperationFormatter.TraceAndSkipElement(reader);
                goto Label_00DC;
            }
Label_010E:
            this.DeserializeParameters(reader, requestMessageInfo.BodyParts, parameters, isRequest);
            if (requestMessageInfo.WrapperName != null)
            {
                reader.ReadEndElement();
            }
            return(obj2);
        }
        void ReadVoidReturn(XmlDictionaryReader reader)
        {
            VerifyIsStartElement(reader, JsonGlobals.dString);
            string typeAttribute = reader.GetAttribute(JsonGlobals.typeString);

            if (!typeAttribute.Equals(JsonGlobals.nullString, StringComparison.Ordinal))
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          XmlObjectSerializer.CreateSerializationException(SR2.GetString(SR2.JsonFormatterExpectedAttributeNull, typeAttribute)));
            }
            OperationFormatter.TraceAndSkipElement(reader);
        }
        private object DeserializeResponse(XmlDictionaryReader reader, object[] parameters)
        {
            if (_responseWrapperName != null)
            {
                if (!reader.IsStartElement(_responseWrapperName, _responseWrapperNamespace))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.SFxInvalidMessageBody, _responseWrapperName, _responseWrapperNamespace, reader.NodeType, reader.Name, reader.NamespaceURI)));
                }

                bool isEmptyElement = reader.IsEmptyElement;
                reader.Read();
                if (isEmptyElement)
                {
                    return(null);
                }
            }

            object returnValue = null;

            if (_returnPart != null)
            {
                while (true)
                {
                    if (IsPartElement(reader, _returnPart))
                    {
                        returnValue = DeserializeParameter(reader, _returnPart);
                        break;
                    }
                    if (!reader.IsStartElement())
                    {
                        break;
                    }

                    if (IsPartElements(reader, _responseParts))
                    {
                        break;
                    }

                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
            DeserializeParameters(reader, _responseParts, parameters);

            if (_responseWrapperName != null)
            {
                reader.ReadEndElement();
            }

            return(returnValue);
        }
        void DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, object[] parameters, PartInfo returnInfo, ref object returnValue)
        {
            bool[] setParameters      = new bool[parameters.Length];
            bool   hasReadReturnValue = false;
            int    currentIndex       = 0;

            while (reader.IsStartElement())
            {
                bool hasReadParameter = false;

                for (int i = 0, index = currentIndex; i < parts.Length; i++, index = (index + 1) % parts.Length)
                {
                    PartInfo part = parts[index];
                    if (part.Serializer.IsStartObject(reader))
                    {
                        currentIndex = i;
                        parameters[part.Description.Index]    = DeserializeParameter(reader, part);
                        setParameters[part.Description.Index] = true;
                        hasReadParameter = true;
                    }
                }

                if (!hasReadParameter)
                {
                    if ((returnInfo != null) && !hasReadReturnValue && returnInfo.Serializer.IsStartObject(reader))
                    {
                        returnValue        = DeserializeParameter(reader, returnInfo);
                        hasReadReturnValue = true;
                    }
                    else
                    {
                        OperationFormatter.TraceAndSkipElement(reader);
                    }
                }
            }

            for (int i = 0; i < parameters.Length; i++)
            {
                if (!setParameters[i])
                {
                    parameters[i] = null;
                }
            }
        }
        void VerifyIsStartElement(XmlDictionaryReader reader, XmlDictionaryString elementName, XmlDictionaryString elementNamespace)
        {
            bool foundElement = false;

            while (reader.IsStartElement())
            {
                if (IsStartElement(reader, elementName, elementNamespace))
                {
                    foundElement = true;
                    break;
                }
                else
                {
                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
            if (!foundElement)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBody, elementName, elementNamespace, reader.NodeType, reader.Name, reader.NamespaceURI)));
            }
        }
Example #9
0
        private object DeserializeResponse(XmlDictionaryReader reader, object[] parameters)
        {
            if (this.responseWrapperName != null)
            {
                if (!reader.IsStartElement(this.responseWrapperName, this.responseWrapperNamespace))
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(System.ServiceModel.SR.GetString("SFxInvalidMessageBody", new object[] { this.responseWrapperName, this.responseWrapperNamespace, reader.NodeType, reader.Name, reader.NamespaceURI })));
                }
                bool isEmptyElement = reader.IsEmptyElement;
                reader.Read();
                if (isEmptyElement)
                {
                    return(null);
                }
            }
            object obj2 = null;

            if (this.returnPart == null)
            {
                goto Label_00CB;
            }
Label_008D:
            if (this.IsPartElement(reader, this.returnPart))
            {
                obj2 = this.DeserializeParameter(reader, this.returnPart);
            }
            else if (reader.IsStartElement() && !this.IsPartElements(reader, this.responseParts))
            {
                OperationFormatter.TraceAndSkipElement(reader);
                goto Label_008D;
            }
Label_00CB:
            this.DeserializeParameters(reader, this.responseParts, parameters);
            if (this.responseWrapperName != null)
            {
                reader.ReadEndElement();
            }
            return(obj2);
        }
        object DeserializeBareMessageContract(XmlDictionaryReader reader, object[] parameters, bool isRequest)
        {
            MessageInfo messageInfo;

            if (isRequest)
            {
                messageInfo = this.requestMessageInfo;
            }
            else
            {
                messageInfo = this.replyMessageInfo;
            }

            if (useAspNetAjaxJson && !isRequest)
            {
                ReadRootElement(reader);
                if (messageInfo.BodyParts.Length == 0)
                {
                    ReadVoidReturn(reader);
                }
            }
            if (messageInfo.BodyParts.Length > 0)
            {
                PartInfo part = messageInfo.BodyParts[0];
                DataContractJsonSerializer serializer = part.Serializer as DataContractJsonSerializer;
                if (useAspNetAjaxJson && !isRequest)
                {
                    serializer = RecreateDataContractJsonSerializer(serializer, JsonGlobals.dString);
                }
                else
                {
                    serializer = RecreateDataContractJsonSerializer(serializer, JsonGlobals.rootString);
                }
                while (reader.IsStartElement())
                {
                    if (serializer.IsStartObject(reader))
                    {
                        try
                        {
                            parameters[part.Description.Index] = part.ReadObject(reader, serializer);
                            break;
                        }
                        catch (System.InvalidOperationException e)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                                              System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBodyErrorDeserializingParameter, part.Description.Namespace, part.Description.Name), e));
                        }
                        catch (System.Runtime.Serialization.InvalidDataContractException e)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(
                                                                                                              System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBodyErrorDeserializingParameter, part.Description.Namespace, part.Description.Name), e));
                        }
                        catch (System.FormatException e)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                      OperationFormatter.CreateDeserializationFailedFault(
                                          System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBodyErrorDeserializingParameterMore,
                                                                           part.Description.Namespace, part.Description.Name, e.Message),
                                          e));
                        }
                        catch (System.Runtime.Serialization.SerializationException e)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                      OperationFormatter.CreateDeserializationFailedFault(
                                          System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBodyErrorDeserializingParameterMore,
                                                                           part.Description.Namespace, part.Description.Name, e.Message),
                                          e));
                        }
                    }
                    else
                    {
                        OperationFormatter.TraceAndSkipElement(reader);
                    }
                }
                while (reader.IsStartElement())
                {
                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
            if (this.useAspNetAjaxJson && !isRequest)
            {
                reader.ReadEndElement();
            }
            return(null);
        }
        protected override object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            if (reader == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
            }
            if (parameters == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parameters"));
            }

            if (reader.EOF)
            {
                return(null);
            }

            if ((isRequest && this.isBareMessageContractRequest) || (!isRequest && isBareMessageContractReply))
            {
                return(DeserializeBareMessageContract(reader, parameters, isRequest));
            }

            object returnValue = null;

            if (isRequest || (isWrapped && !useAspNetAjaxJson))
            {
                ValidateTypeObjectAttribute(reader, isRequest);
                returnValue = DeserializeBodyCore(reader, parameters, isRequest);
            }
            else
            {
                if (useAspNetAjaxJson)
                {
                    ReadRootElement(reader);
                }
                if (useAspNetAjaxJson && messageDescription.IsVoid)
                {
                    ReadVoidReturn(reader);
                }
                else if (replyMessageInfo.ReturnPart != null)
                {
                    PartInfo part = replyMessageInfo.ReturnPart;
                    DataContractJsonSerializer serializer = part.Serializer as DataContractJsonSerializer;

                    if (useAspNetAjaxJson)
                    {
                        serializer = RecreateDataContractJsonSerializer(serializer, JsonGlobals.dString);
                        VerifyIsStartElement(reader, JsonGlobals.dString);
                    }
                    else
                    {
                        serializer = RecreateDataContractJsonSerializer(serializer, JsonGlobals.rootString);
                        VerifyIsStartElement(reader, JsonGlobals.rootString);
                    }

                    if (serializer.IsStartObject(reader))
                    {
                        try
                        {
                            returnValue = part.ReadObject(reader, serializer);
                        }
                        catch (System.InvalidOperationException e)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                                              System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBodyErrorDeserializingParameter, part.Description.Namespace, part.Description.Name), e));
                        }
                        catch (System.Runtime.Serialization.InvalidDataContractException e)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new System.Runtime.Serialization.InvalidDataContractException(
                                                                                                              System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBodyErrorDeserializingParameter, part.Description.Namespace, part.Description.Name), e));
                        }
                        catch (System.FormatException e)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                      OperationFormatter.CreateDeserializationFailedFault(
                                          System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBodyErrorDeserializingParameterMore,
                                                                           part.Description.Namespace, part.Description.Name, e.Message),
                                          e));
                        }
                        catch (System.Runtime.Serialization.SerializationException e)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                      OperationFormatter.CreateDeserializationFailedFault(
                                          System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInvalidMessageBodyErrorDeserializingParameterMore,
                                                                           part.Description.Namespace, part.Description.Name, e.Message),
                                          e));
                        }
                    }
                }
                else if (replyMessageInfo.BodyParts != null)
                {
                    ValidateTypeObjectAttribute(reader, isRequest);
                    returnValue = DeserializeBodyCore(reader, parameters, isRequest);
                }

                while (reader.IsStartElement())
                {
                    OperationFormatter.TraceAndSkipElement(reader);
                }

                if (useAspNetAjaxJson)
                {
                    reader.ReadEndElement();
                }
            }

            return(returnValue);
        }
        protected override object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
            }
            if (parameters == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parameters"));
            }

            MessageInfo messageInfo;

            if (isRequest)
            {
                messageInfo = requestMessageInfo;
            }
            else
            {
                messageInfo = replyMessageInfo;
            }

            if (messageInfo.WrapperName != null)
            {
                if (!reader.IsStartElement(messageInfo.WrapperName, messageInfo.WrapperNamespace))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.SFxInvalidMessageBody, messageInfo.WrapperName, messageInfo.WrapperNamespace, reader.NodeType, reader.Name, reader.NamespaceURI)));
                }
                bool isEmptyElement = reader.IsEmptyElement;
                reader.Read();
                if (isEmptyElement)
                {
                    return(null);
                }
            }
            object returnValue = null;

            if (messageInfo.ReturnPart != null)
            {
                while (true)
                {
                    PartInfo part = messageInfo.ReturnPart;
                    if (part.Serializer.IsStartObject(reader))
                    {
                        returnValue = DeserializeParameter(reader, part, isRequest);
                        break;
                    }
                    if (!reader.IsStartElement())
                    {
                        break;
                    }
                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
            DeserializeParameters(reader, messageInfo.BodyParts, parameters, isRequest);
            if (messageInfo.WrapperName != null)
            {
                reader.ReadEndElement();
            }
            return(returnValue);
        }