Exemple #1
0
        public void DeserializeRequest(Message message, object[] parameters)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }

            if (parameters == null)
            {
                throw TraceUtility.ThrowHelperError(new ArgumentNullException("parameters"), message);
            }

            try
            {
                if (_requestDescription.IsTypedMessage)
                {
                    object            typeMessageInstance = CreateTypedMessageInstance(_requestDescription.MessageType);
                    TypedMessageParts typedMessageParts   = new TypedMessageParts(typeMessageInstance, _requestDescription);
                    object[]          parts = new object[typedMessageParts.Count];

                    GetPropertiesFromMessage(message, _requestDescription, parts);
                    GetHeadersFromMessage(message, _requestDescription, parts, true /*isRequest*/);
                    DeserializeBodyContents(message, parts, true /*isRequest*/);

                    // copy values into the actual field/properties
                    typedMessageParts.SetTypedMessageParts(parts);

                    parameters[0] = typeMessageInstance;
                }
                else
                {
                    GetPropertiesFromMessage(message, _requestDescription, parameters);
                    GetHeadersFromMessage(message, _requestDescription, parameters, true /*isRequest*/);
                    DeserializeBodyContents(message, parameters, true /*isRequest*/);
                }
            }
            catch (XmlException xe)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          OperationFormatter.CreateDeserializationFailedFault(
                              SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operationName, xe.Message),
                              xe));
            }
            catch (FormatException fe)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          OperationFormatter.CreateDeserializationFailedFault(
                              SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operationName, fe.Message),
                              fe));
            }
            catch (SerializationException se)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operationName, se.Message),
                                                                              se));
            }
        }
        public void DeserializeRequest(Message message, object[] parameters)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(message)));
            }

            if (parameters == null)
            {
                throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(parameters)), message);
            }

            try
            {
                if (message.IsEmpty)
                {
                    if (_requestWrapperName == null)
                    {
                        return;
                    }

                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.SFxInvalidMessageBodyEmptyMessage));
                }

                XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents();
                using (bodyReader)
                {
                    DeserializeRequest(bodyReader, parameters);
                    message.ReadFromBodyContentsToEnd(bodyReader);
                }
            }
            catch (XmlException xe)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          OperationFormatter.CreateDeserializationFailedFault(
                              SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operation.Name, xe.Message),
                              xe));
            }
            catch (FormatException fe)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          OperationFormatter.CreateDeserializationFailedFault(
                              SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operation.Name, fe.Message),
                              fe));
            }
            catch (SerializationException se)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operation.Name, se.Message),
                                                                              se));
            }
        }
        object DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part)
        {
            object val;

            try
            {
                val = part.ReadObject(reader);
            }
            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));
            }

            return(val);
        }
Exemple #4
0
        private object DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, bool isRequest)
        {
            object val;

            try
            {
                val = part.ReadObject(reader);
            }
            catch (InvalidOperationException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.Format(SR.SFxInvalidMessageBodyErrorDeserializingParameter, part.Description.Namespace, part.Description.Name), e));
            }
            catch (InvalidDataContractException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(
                                                                              SR.Format(SR.SFxInvalidMessageBodyErrorDeserializingParameter, part.Description.Namespace, part.Description.Name), e));
            }
            catch (FormatException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          OperationFormatter.CreateDeserializationFailedFault(
                              SR.Format(SR.SFxInvalidMessageBodyErrorDeserializingParameterMore,
                                        part.Description.Namespace, part.Description.Name, e.Message),
                              e));
            }
            catch (SerializationException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          OperationFormatter.CreateDeserializationFailedFault(
                              SR.Format(SR.SFxInvalidMessageBodyErrorDeserializingParameterMore,
                                        part.Description.Namespace, part.Description.Name, e.Message),
                              e));
            }

            return(val);
        }
        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);
        }
Exemple #7
0
        private object DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, bool isRequest)
        {
            object obj2;
            XmlObjectSerializer serializer = part.Serializer;

            try
            {
                obj2 = serializer.ReadObject(reader, false);
            }
            catch (InvalidOperationException exception)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidMessageBodyErrorDeserializingParameter", new object[] { part.Description.Namespace, part.Description.Name }), exception));
            }
            catch (InvalidDataContractException exception2)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.ServiceModel.SR.GetString("SFxInvalidMessageBodyErrorDeserializingParameter", new object[] { part.Description.Namespace, part.Description.Name }), exception2));
            }
            catch (FormatException exception3)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(OperationFormatter.CreateDeserializationFailedFault(System.ServiceModel.SR.GetString("SFxInvalidMessageBodyErrorDeserializingParameterMore", new object[] { part.Description.Namespace, part.Description.Name, exception3.Message }), exception3));
            }
            catch (SerializationException exception4)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(OperationFormatter.CreateDeserializationFailedFault(System.ServiceModel.SR.GetString("SFxInvalidMessageBodyErrorDeserializingParameterMore", new object[] { part.Description.Namespace, part.Description.Name, exception4.Message }), exception4));
            }
            return(obj2);
        }
Exemple #8
0
 public void DeserializeRequest(Message message, object[] parameters)
 {
     if (message == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
     }
     if (parameters == null)
     {
         throw TraceUtility.ThrowHelperError(new ArgumentNullException("parameters"), message);
     }
     try
     {
         if (message.IsEmpty)
         {
             if (this.requestWrapperName != null)
             {
                 throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(System.ServiceModel.SR.GetString("SFxInvalidMessageBodyEmptyMessage")));
             }
         }
         else
         {
             XmlDictionaryReader readerAtBodyContents = message.GetReaderAtBodyContents();
             using (readerAtBodyContents)
             {
                 this.DeserializeRequest(readerAtBodyContents, parameters);
                 message.ReadFromBodyContentsToEnd(readerAtBodyContents);
             }
         }
     }
     catch (XmlException exception)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(OperationFormatter.CreateDeserializationFailedFault(System.ServiceModel.SR.GetString("SFxErrorDeserializingRequestBodyMore", new object[] { this.operation.Name, exception.Message }), exception));
     }
     catch (FormatException exception2)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(OperationFormatter.CreateDeserializationFailedFault(System.ServiceModel.SR.GetString("SFxErrorDeserializingRequestBodyMore", new object[] { this.operation.Name, exception2.Message }), exception2));
     }
     catch (SerializationException exception3)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorDeserializingRequestBodyMore", new object[] { this.operation.Name, exception3.Message }), exception3));
     }
 }