internal override void InferMessageDescription(OperationDescription operation, object owner, MessageDirection direction)
        {
            ContractInferenceHelper.CheckForDisposableParameters(operation, this.InternalDeclaredMessageType);
            string           overridingAction       = null;
            SerializerOption dataContractSerializer = SerializerOption.DataContractSerializer;
            Receive          receive = owner as Receive;

            if (receive != null)
            {
                overridingAction       = receive.Action;
                dataContractSerializer = receive.SerializerOption;
            }
            else
            {
                ReceiveReply reply = owner as ReceiveReply;
                overridingAction       = reply.Action;
                dataContractSerializer = reply.Request.SerializerOption;
            }
            if (direction == MessageDirection.Input)
            {
                ContractInferenceHelper.AddInputMessage(operation, overridingAction, this.InternalDeclaredMessageType, dataContractSerializer);
            }
            else
            {
                ContractInferenceHelper.AddOutputMessage(operation, overridingAction, this.InternalDeclaredMessageType, dataContractSerializer);
            }
        }
Ejemplo n.º 2
0
        private static void EmitStringSerialize(ILGenerator il, FieldInfo field, SerializerOption option)
        {
            EmitEncoding(il, field);
            MethodInfo method = option == SerializerOption.Normal ? s_WriteValueStringWithIndexMethod : s_WriteValueStringMethod;

            il.Emit(OpCodes.Call, method);
        }
Ejemplo n.º 3
0
        internal override void InferMessageDescription(OperationDescription operation, object owner, MessageDirection direction)
        {
            ContractInferenceHelper.CheckForDisposableParameters(operation, this.InternalDeclaredMessageType);

            string           overridingAction = null;
            SerializerOption serializerOption = SerializerOption.DataContractSerializer;
            Send             send             = owner as Send;

            if (send != null)
            {
                overridingAction = send.Action;
                serializerOption = send.SerializerOption;
            }
            else
            {
                SendReply sendReply = owner as SendReply;
                Fx.Assert(sendReply != null, "The owner of SendMessageContent can only be Send or SendReply!");
                overridingAction = sendReply.Action;
                serializerOption = sendReply.Request.SerializerOption;
            }

            if (direction == MessageDirection.Input)
            {
                ContractInferenceHelper.AddInputMessage(operation, overridingAction, this.InternalDeclaredMessageType, serializerOption);
            }
            else
            {
                ContractInferenceHelper.AddOutputMessage(operation, overridingAction, this.InternalDeclaredMessageType, serializerOption);
            }
        }
 private static void EmitComplexDeserialize(ILGenerator il, Type type, SerializerOption option)
 {
     if (option == SerializerOption.CompactLayout)
     {
         il.Emit(OpCodes.Call, s_IteratorNextAsComplexWithoutTagMethod.MakeGenericMethod(type));
     }
     else
     {
         il.Emit(OpCodes.Call, s_IteratorNextAsComplexMethod.MakeGenericMethod(type));
     }
 }
Ejemplo n.º 5
0
        static void AddSerializerProvider(OperationDescription operation, SerializerOption serializerOption)
        {
            switch (serializerOption)
            {
            case SerializerOption.DataContractSerializer:
                AddDataContractSerializerFormat(operation);
                break;

            case SerializerOption.XmlSerializer:
                AddXmlSerializerFormat(operation);
                break;
            }
        }
Ejemplo n.º 6
0
        private static void EmitComplexSerialize(ILGenerator il, Type type, SerializerOption option)
        {
            MethodInfo method;

            if (option == SerializerOption.Normal)
            {
                method = s_WriteValueComplexWithIndexMethod.MakeGenericMethod(type);
            }
            else
            {
                method = s_WriteValueComplexTypesMethod.MakeGenericMethod(type);
            }

            il.Emit(OpCodes.Call, method);
        }
Ejemplo n.º 7
0
        private static void EmitFloatSerialize(ILGenerator il, Type type, SerializerOption option)
        {
            MethodInfo method;

            if (option == SerializerOption.Normal)
            {
                s_WriteValueFloatWithIndexTypes[1] = type;
                method = s_WriterType.GetMethod(Resources.WriteValueMethodName, s_WriteValueFloatWithIndexTypes);
            }
            else
            {
                s_WriteValueFloatTypes[0] = type;
                method = s_WriterType.GetMethod(Resources.WriteValueMethodName, s_WriteValueFloatTypes);
            }

            il.Emit(OpCodes.Call, method);
        }
Ejemplo n.º 8
0
        public static MessageDescription CreateMessageDescription(OperationDescription operation, bool isResponse,
            MessageDirection direction, string overridingAction, Type type, SerializerOption serializerOption)
        {
            MessageDescription result;
            if (type != null && IsMessageContract(type))
            {
                result = CreateFromMessageContract(operation, isResponse, direction, overridingAction, type);
            }
            else
            {
                // For Send/Receive, we do not wrap message
                result = CreateEmptyMessageDescription(operation, isResponse, direction, overridingAction);
                AddMessagePartDescription(operation, isResponse, result, type, serializerOption);
            }

            return result;
        }
Ejemplo n.º 9
0
        internal static Type InjectType <T>()
        {
            Type        objType       = typeof(T);
            Type        interfaceType = typeof(ITypeSerializer <T>);
            TypeBuilder builder       = CreateBuilder(objType, interfaceType);

            GetSerializedFields(objType);
            GetMessageCallbacks(objType);

            SerializerOption option = objType.GetCustomAttribute <CompactLayoutAttribute>(true) == null
                ? SerializerOption.Normal : SerializerOption.CompactLayout;

            for (int i = 0; i < s_Progress.Length; i++)
            {
                s_Progress[i].Execute(objType, interfaceType, builder, s_FieldData, s_MethodData, option);
            }

            return(builder.CreateType());
        }
 public static void AddMessagePartDescription(OperationDescription operation, bool isResponse, MessageDescription message, Type type, SerializerOption serializerOption)
 {
     if (type != null)
     {
         string name;
         string str2;
         if (serializerOption == SerializerOption.DataContractSerializer)
         {
             XmlQualifiedName rootElementName = XsdDataContractExporter.GetRootElementName(type);
             if (rootElementName == null)
             {
                 rootElementName = XsdDataContractExporter.GetSchemaTypeName(type);
             }
             if (!rootElementName.IsEmpty)
             {
                 name = rootElementName.Name;
                 str2 = rootElementName.Namespace;
             }
             else
             {
                 name = type.Name;
                 str2 = operation.DeclaringContract.Namespace;
             }
         }
         else
         {
             XmlTypeMapping mapping = XmlReflectionImporter.ImportTypeMapping(type);
             name = mapping.ElementName;
             str2 = mapping.Namespace;
         }
         MessagePartDescription item = new MessagePartDescription(NamingHelper.XmlName(name), str2) {
             Index = 0,
             Type = type
         };
         message.Body.Parts.Add(item);
     }
     if (isResponse)
     {
         SetReturnValue(message, operation);
     }
 }
Ejemplo n.º 11
0
 public abstract void Execute(Type objType, Type interfaceType, TypeBuilder builder, List <FieldData> fields, List <MethodData> methods, SerializerOption option);
        public static void ValidateMessageContent(NativeActivityContext context, MessageDescription targetMessage, Type declaredMessageType,
            SerializerOption serializerOption, OperationDescription operation, bool isResponse)
        {
            // MessageContract is allowed only if the WCF contract interface specifies the same message contract type.
            if (MessageBuilder.IsMessageContract(declaredMessageType))
            {
                // if it is a typed message contract, we just validate the type of the message matches
                if (targetMessage.MessageType != null )
                {
                    if (declaredMessageType != targetMessage.MessageType)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(declaredMessageType.ToString(), "type", targetMessage.MessageType.ToString(), operation.Name, operation.DeclaringContract.Name)));
                    }
                }
                else
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(declaredMessageType.ToString(), "type", "null", operation.Name, operation.DeclaringContract.Name))); 
                }
                return;
            }
            else if (declaredMessageType != null && declaredMessageType.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
            {
                //This is an untyped message contract
                if (targetMessage.Body == null)
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.BodyCannotBeNull));
                }
                else
                {
                    if (isResponse)
                    {
                        if (targetMessage.Body.ReturnValue == null)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ExtraReturnValue));
                        }
                        else if (!targetMessage.Body.ReturnValue.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.FirstParameterDoesnotMatchTheReturnValue(declaredMessageType.FullName, targetMessage.Body.ReturnValue.Type.Name, operation.Name, operation.DeclaringContract.Name)));
                        }
                    }
                    else
                    {
                        if (targetMessage.Body.Parts.Count == 0)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterNumberMismatch(declaredMessageType.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                        else if (targetMessage.Body.Parts.Count > 1)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.MessageContentCannotHaveMoreThanOneParameter(operation.Name, operation.DeclaringContract.Name)));
                        }
                        else
                        {
                            if (!targetMessage.Body.Parts[0].Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
                            {
                                Constraint.AddValidationError(context, new ValidationError(SR2.MessageTypeMismatch(targetMessage.Body.Parts[0].Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                            }
                        }
                    }
                }

                return;
            }

            // In case the WCF contract is a typed message, and the Receive activity also uses ReceiveMessageContent to infer a typed message, the contract needs to be matched
            Fx.Assert(targetMessage.Body != null, "MessageDescription.Body is never null!");

            // MessageDescription: Headers, Properties, ProtectionLevel
            // MessageBodyDescription: ReturnValue, WrapperName, WrapperNamespace
            // MessagePartDescription: Name, Namespace, Type, ProtectionLevel, Multiple, Index
            if (targetMessage.Headers.Count > 0)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.MessageHeaderNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }
            if (targetMessage.Properties.Count > 0)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.MessagePropertyIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }
            if (targetMessage.HasProtectionLevel)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.ProtectionLevelIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }
            
            if (declaredMessageType == null || declaredMessageType == TypeHelper.VoidType)
            {
                if (!targetMessage.IsVoid)
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.MessageCannotBeEmpty(operation.Name, operation.DeclaringContract.Name)));
                }
            }
            else
            {
                string partName;
                string partNamespace;

                if (serializerOption == SerializerOption.DataContractSerializer)
                {
                    XmlQualifiedName xmlQualifiedName = MessageBuilder.XsdDataContractExporter.GetRootElementName(declaredMessageType);
                    if (xmlQualifiedName == null)
                    {
                        xmlQualifiedName = MessageBuilder.XsdDataContractExporter.GetSchemaTypeName(declaredMessageType);
                    }

                    if (!xmlQualifiedName.IsEmpty)
                    {
                        partName = xmlQualifiedName.Name;
                        partNamespace = xmlQualifiedName.Namespace;
                    }
                    else
                    {
                        // For anonymous type, we assign CLR type name and contract namespace to MessagePartDescription
                        partName = declaredMessageType.Name;
                        partNamespace = operation.DeclaringContract.Namespace;
                    }
                }
                else
                {
                    XmlTypeMapping xmlTypeMapping = MessageBuilder.XmlReflectionImporter.ImportTypeMapping(declaredMessageType);
                    partName = xmlTypeMapping.ElementName;
                    partNamespace = xmlTypeMapping.Namespace;
                }

                MessagePartDescription targetPart = null;

                if (isResponse && targetMessage.Body.ReturnValue != null && targetMessage.Body.ReturnValue.Type != TypeHelper.VoidType)
                {
                    if (targetMessage.Body.Parts.Count > 0)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.NotSupportMoreThanOneParametersInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }
                    targetPart = targetMessage.Body.ReturnValue;
                }
                else if (!isResponse)
                {
                    if (targetMessage.Body.WrapperName != null && targetMessage.Body.WrapperName != String.Empty)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.WrapperNotSupportedInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }

                    if (targetMessage.Body.WrapperNamespace != null && targetMessage.Body.WrapperNamespace != String.Empty)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.WrapperNotSupportedInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }

                    if (targetMessage.Body.Parts.Count == 0)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.ParameterNumberMismatch(declaredMessageType.FullName, operation.Name, operation.DeclaringContract.Name)));
                    }
                    else if (targetMessage.Body.Parts.Count > 1)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.MessageContentCannotHaveMoreThanOneParameter(operation.Name, operation.DeclaringContract.Name)));
                    }
                    else
                    {
                        targetPart = targetMessage.Body.Parts[0];
                    }
                }

                if (targetPart != null)
                {
                    if (partName != targetPart.Name)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(partName, "parameter name", targetPart.Name, operation.Name, operation.DeclaringContract.Name)));
                    }
                    if (partNamespace != targetPart.Namespace)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(partNamespace, "parameter namespace", targetPart.Namespace, operation.Name, operation.DeclaringContract.Name)));
                    }
                    if (declaredMessageType != targetPart.Type)
                    {
                        if (declaredMessageType != null)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterTypeMismatch(declaredMessageType.FullName, targetPart.Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                        else
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterTypeMismatch(TypeHelper.VoidType.FullName, targetPart.Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                    }
                    if (targetPart.HasProtectionLevel)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.ProtectionLevelIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
                    }

                    // Multiple and Index do not need to be validate because there is only one part in the message.
                }
            }
        }
 public static MessageDescription CreateMessageDescription(OperationDescription operation, bool isResponse, MessageDirection direction, string overridingAction, Type type, SerializerOption serializerOption)
 {
     if ((type != null) && IsMessageContract(type))
     {
         return CreateFromMessageContract(operation, isResponse, direction, overridingAction, type);
     }
     MessageDescription message = CreateEmptyMessageDescription(operation, isResponse, direction, overridingAction);
     AddMessagePartDescription(operation, isResponse, message, type, serializerOption);
     return message;
 }
Ejemplo n.º 14
0
        public static void AddInputMessage(OperationDescription operation, string overridingAction, Type type, SerializerOption serializerOption)
        {
            Fx.Assert(operation.Messages.Count == 0, "Operation already has input message");

            bool isResponse            = false;
            MessageDescription message = MessageBuilder.CreateMessageDescription(
                operation, isResponse, MessageDirection.Input, overridingAction, type, serializerOption);

            operation.Messages.Add(message);
        }
        private void EmitIL(ILGenerator il, Type objType, List <FieldData> fields, List <MethodData> methods, SerializerOption option)
        {
            if (option == SerializerOption.Normal)
            {
                EmitFieldsDeserializeNormal(il, objType, fields);
            }
            else
            {
                EmitFieldsDeserializeCompact(il, objType, fields);
            }

            for (int i = 0; i < methods.Count; i++)
            {
                MethodData data = methods[i];

                if (data.Type == AccelbufferCallback.OnAfterDeserialization)
                {
                    EmitMessageCallback(il, objType, data.Method);
                }
            }
        }
        public static void AddOutputMessage(OperationDescription operation, string overridingAction, Type type, SerializerOption serializerOption)
        {
            Fx.Assert(operation.Messages.Count > 0, "Operation does not have input message");
            Fx.Assert(operation.Messages.Count < 2, "Operation already has output message");

            bool isResponse = true;
            MessageDescription message = MessageBuilder.CreateMessageDescription(
                operation, isResponse, MessageDirection.Output, overridingAction, type, serializerOption);

            operation.Messages.Add(message);
        }
Ejemplo n.º 17
0
        public static MessageDescription CreateMessageDescription(OperationDescription operation, bool isResponse,
                                                                  MessageDirection direction, string overridingAction, Type type, SerializerOption serializerOption)
        {
            MessageDescription result;

            if (type != null && IsMessageContract(type))
            {
                result = CreateFromMessageContract(operation, isResponse, direction, overridingAction, type);
            }
            else
            {
                // For Send/Receive, we do not wrap message
                result = CreateEmptyMessageDescription(operation, isResponse, direction, overridingAction);
                AddMessagePartDescription(operation, isResponse, result, type, serializerOption);
            }

            return(result);
        }
        private static void EmitCharDeserialize(ILGenerator il, FieldInfo field, string name, SerializerOption option)
        {
            MethodInfo method;

            if (option == SerializerOption.CompactLayout)
            {
                EmitEncoding(il, field);
                method = s_IteratorType.GetMethod(string.Format(Resources.NextAsWithoutTagName, name));
            }
            else
            {
                method = s_IteratorType.GetMethod(Resources.NextAsName + name);
            }

            il.Emit(OpCodes.Call, method);
        }
Ejemplo n.º 19
0
        public static void AddMessagePartDescription(OperationDescription operation, bool isResponse,
            MessageDescription message, Type type, SerializerOption serializerOption)
        {
            if (type != null)
            {
                string partName;
                string partNamespace;

                if (serializerOption == SerializerOption.DataContractSerializer)
                {
                    XmlQualifiedName xmlQualifiedName = XsdDataContractExporter.GetRootElementName(type);
                    if (xmlQualifiedName == null)
                    {
                        xmlQualifiedName = XsdDataContractExporter.GetSchemaTypeName(type);
                    }

                    if (!xmlQualifiedName.IsEmpty)
                    {
                        partName = xmlQualifiedName.Name;
                        partNamespace = xmlQualifiedName.Namespace;
                    }
                    else
                    {
                        // For anonymous type, we assign CLR type name and contract namespace to MessagePartDescription
                        partName = type.Name;
                        partNamespace = operation.DeclaringContract.Namespace;
                    }
                }
                else
                {
                    XmlTypeMapping xmlTypeMapping = XmlReflectionImporter.ImportTypeMapping(type);
                    partName = xmlTypeMapping.ElementName;
                    partNamespace = xmlTypeMapping.Namespace;
                }

                MessagePartDescription messagePart = new MessagePartDescription(NamingHelper.XmlName(partName), partNamespace)
                {
                    Index = 0,
                    Type = type

                    // We do not infer MessagePartDescription.ProtectionLevel
                };

                message.Body.Parts.Add(messagePart);
            }
            
            if (isResponse)
            {
                SetReturnValue(message, operation);
            }
        }
Ejemplo n.º 20
0
        private static void EmitBooleanSerialize(ILGenerator il, SerializerOption option)
        {
            MethodInfo method = option == SerializerOption.Normal ? s_WriteValueBoolWithIndexMethod : s_WriteValueBoolMethod;

            il.Emit(OpCodes.Call, method);
        }
 public static void AddInputMessage(OperationDescription operation, string overridingAction, System.Type type, SerializerOption serializerOption)
 {
     bool isResponse = false;
     MessageDescription item = MessageBuilder.CreateMessageDescription(operation, isResponse, MessageDirection.Input, overridingAction, type, serializerOption);
     operation.Messages.Add(item);
 }
Ejemplo n.º 22
0
        private static void EmitIntSerialize(ILGenerator il, FieldInfo field, Type type, SerializerOption option)
        {
            EmitNumberFormat(il, field);
            MethodInfo method;

            if (type.IsEnum)
            {
                type = Enum.GetUnderlyingType(type);
            }

            if (option == SerializerOption.Normal)
            {
                s_WriteValueIntWithIndexTypes[1] = type;
                method = s_WriterType.GetMethod(Resources.WriteValueMethodName, s_WriteValueIntWithIndexTypes);
            }
            else
            {
                s_WriteValueIntTypes[0] = type;
                method = s_WriterType.GetMethod(Resources.WriteValueMethodName, s_WriteValueIntTypes);
            }

            il.Emit(OpCodes.Call, method);
        }
Ejemplo n.º 23
0
 public override void Execute(Type objType, Type interfaceType, TypeBuilder builder, List <FieldData> fields, List <MethodData> methods, SerializerOption option)
 {
     builder.DefineDefaultConstructor(MethodAttributes.Public);
 }
        public override void Execute(Type objType, Type interfaceType, TypeBuilder builder, List <FieldData> fields, List <MethodData> methods, SerializerOption option)
        {
            MethodBuilder method = builder.DefineMethod(Resources.DeserializeMethodName,
                                                        s_MethodAttributes,
                                                        s_CallingConventions,
                                                        objType,
                                                        s_DeserializeTypes);

            ILGenerator il = method.GetILGenerator();

            Predefine(il, objType);
            EmitIL(il, objType, fields, methods, option);

            il.Emit(OpCodes.Ldloc_0);
            il.Emit(OpCodes.Ret);

            builder.DefineMethodOverride(method, interfaceType.GetMethod(Resources.DeserializeMethodName));
        }
Ejemplo n.º 25
0
        private void EmitIL(ILGenerator il, Type objType, List <FieldData> fields, List <MethodData> methods, SerializerOption option)
        {
            for (int i = 0; i < methods.Count; i++)
            {
                MethodData data = methods[i];

                if (data.Type == AccelbufferCallback.OnBeforeSerialization)
                {
                    EmitMessageCallback(il, objType, data.Method);
                }
            }

            for (int i = 0; i < fields.Count; i++)
            {
                FieldData data = fields[i];
                EmitFieldSerialize(il, data.Field, data.Index, data.CheckRef, option);
            }
        }
        private static void EmitFloatAndBooleanDeserialize(ILGenerator il, string name, SerializerOption option)
        {
            name = option == SerializerOption.CompactLayout ? string.Format(Resources.NextAsWithoutTagName, name) : Resources.NextAsName + name;
            MethodInfo method = s_IteratorType.GetMethod(name);

            il.Emit(OpCodes.Call, method);
        }
Ejemplo n.º 27
0
        private static void EmitFieldSerialize(ILGenerator il, FieldInfo field, int index, bool checkRef, SerializerOption option)
        {
            Type     fieldType = field.FieldType;
            WireType type      = GetWireType(field.FieldType, out _);
            Label    label     = default;

            if (checkRef && (!fieldType.IsValueType) && (option == SerializerOption.Normal))
            {
                label = il.DefineLabel();
                il.Emit(OpCodes.Ldarg_1);      //arg
                il.Emit(OpCodes.Ldfld, field); //field
                il.Emit(OpCodes.Brfalse, label);
            }

            il.Emit(OpCodes.Ldarg_2);//writer

            if (option == SerializerOption.Normal)
            {
                il.Emit(OpCodes.Ldc_I4, index);//index
            }

            il.Emit(OpCodes.Ldarg_1);      //arg
            il.Emit(OpCodes.Ldfld, field); //field

            switch (type)
            {
            case WireType.Int:
                EmitIntSerialize(il, field, fieldType, option);
                break;

            case WireType.Float:
                EmitFloatSerialize(il, fieldType, option);
                break;

            case WireType.Char:
                EmitCharSerialize(il, field, option);
                break;

            case WireType.String:
                EmitStringSerialize(il, field, option);
                break;

            case WireType.Boolean:
                EmitBooleanSerialize(il, option);
                break;

            default:
                EmitComplexSerialize(il, fieldType, option);
                break;
            }

            if (checkRef && (!fieldType.IsValueType) && (option == SerializerOption.Normal))
            {
                il.MarkLabel(label);
            }
        }
        public static void AddInputMessage(OperationDescription operation, string overridingAction, System.Type type, SerializerOption serializerOption)
        {
            bool isResponse         = false;
            MessageDescription item = MessageBuilder.CreateMessageDescription(operation, isResponse, MessageDirection.Input, overridingAction, type, serializerOption);

            operation.Messages.Add(item);
        }
Ejemplo n.º 29
0
        public static MessageDescription CreateMessageDescription(OperationDescription operation, bool isResponse, MessageDirection direction, string overridingAction, Type type, SerializerOption serializerOption)
        {
            if ((type != null) && IsMessageContract(type))
            {
                return(CreateFromMessageContract(operation, isResponse, direction, overridingAction, type));
            }
            MessageDescription message = CreateEmptyMessageDescription(operation, isResponse, direction, overridingAction);

            AddMessagePartDescription(operation, isResponse, message, type, serializerOption);
            return(message);
        }
        public static void AddInputMessage(OperationDescription operation, string overridingAction, Type type, SerializerOption serializerOption)
        {
            Fx.Assert(operation.Messages.Count == 0, "Operation already has input message");

            bool isResponse = false;
            MessageDescription message = MessageBuilder.CreateMessageDescription(
                operation, isResponse, MessageDirection.Input, overridingAction, type, serializerOption);

            operation.Messages.Add(message);
        }
Ejemplo n.º 31
0
 public static void AddMessagePartDescription(OperationDescription operation, bool isResponse, MessageDescription message, Type type, SerializerOption serializerOption)
 {
     if (type != null)
     {
         string name;
         string str2;
         if (serializerOption == SerializerOption.DataContractSerializer)
         {
             XmlQualifiedName rootElementName = XsdDataContractExporter.GetRootElementName(type);
             if (rootElementName == null)
             {
                 rootElementName = XsdDataContractExporter.GetSchemaTypeName(type);
             }
             if (!rootElementName.IsEmpty)
             {
                 name = rootElementName.Name;
                 str2 = rootElementName.Namespace;
             }
             else
             {
                 name = type.Name;
                 str2 = operation.DeclaringContract.Namespace;
             }
         }
         else
         {
             XmlTypeMapping mapping = XmlReflectionImporter.ImportTypeMapping(type);
             name = mapping.ElementName;
             str2 = mapping.Namespace;
         }
         MessagePartDescription item = new MessagePartDescription(NamingHelper.XmlName(name), str2)
         {
             Index = 0,
             Type  = type
         };
         message.Body.Parts.Add(item);
     }
     if (isResponse)
     {
         SetReturnValue(message, operation);
     }
 }
 static void AddSerializerProvider(OperationDescription operation, SerializerOption serializerOption)
 {
     switch (serializerOption)
     {
         case SerializerOption.DataContractSerializer:
             AddDataContractSerializerFormat(operation);
             break;
         case SerializerOption.XmlSerializer:
             AddXmlSerializerFormat(operation);
             break;
     }
 }
        public static void ValidateMessageContent(NativeActivityContext context, MessageDescription targetMessage, Type declaredMessageType,
                                                  SerializerOption serializerOption, OperationDescription operation, bool isResponse)
        {
            // MessageContract is allowed only if the WCF contract interface specifies the same message contract type.
            if (MessageBuilder.IsMessageContract(declaredMessageType))
            {
                // if it is a typed message contract, we just validate the type of the message matches
                if (targetMessage.MessageType != null)
                {
                    if (declaredMessageType != targetMessage.MessageType)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(declaredMessageType.ToString(), "type", targetMessage.MessageType.ToString(), operation.Name, operation.DeclaringContract.Name)));
                    }
                }
                else
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(declaredMessageType.ToString(), "type", "null", operation.Name, operation.DeclaringContract.Name)));
                }
                return;
            }
            else if (declaredMessageType != null && declaredMessageType.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
            {
                //This is an untyped message contract
                if (targetMessage.Body == null)
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.BodyCannotBeNull));
                }
                else
                {
                    if (isResponse)
                    {
                        if (targetMessage.Body.ReturnValue == null)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ExtraReturnValue));
                        }
                        else if (!targetMessage.Body.ReturnValue.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.FirstParameterDoesnotMatchTheReturnValue(declaredMessageType.FullName, targetMessage.Body.ReturnValue.Type.Name, operation.Name, operation.DeclaringContract.Name)));
                        }
                    }
                    else
                    {
                        if (targetMessage.Body.Parts.Count == 0)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterNumberMismatch(declaredMessageType.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                        else if (targetMessage.Body.Parts.Count > 1)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.MessageContentCannotHaveMoreThanOneParameter(operation.Name, operation.DeclaringContract.Name)));
                        }
                        else
                        {
                            if (!targetMessage.Body.Parts[0].Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
                            {
                                Constraint.AddValidationError(context, new ValidationError(SR2.MessageTypeMismatch(targetMessage.Body.Parts[0].Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                            }
                        }
                    }
                }

                return;
            }

            // In case the WCF contract is a typed message, and the Receive activity also uses ReceiveMessageContent to infer a typed message, the contract needs to be matched
            Fx.Assert(targetMessage.Body != null, "MessageDescription.Body is never null!");

            // MessageDescription: Headers, Properties, ProtectionLevel
            // MessageBodyDescription: ReturnValue, WrapperName, WrapperNamespace
            // MessagePartDescription: Name, Namespace, Type, ProtectionLevel, Multiple, Index
            if (targetMessage.Headers.Count > 0)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.MessageHeaderNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }
            if (targetMessage.Properties.Count > 0)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.MessagePropertyIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }
            if (targetMessage.HasProtectionLevel)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.ProtectionLevelIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }

            if (declaredMessageType == null || declaredMessageType == TypeHelper.VoidType)
            {
                if (!targetMessage.IsVoid)
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.MessageCannotBeEmpty(operation.Name, operation.DeclaringContract.Name)));
                }
            }
            else
            {
                string partName;
                string partNamespace;

                if (serializerOption == SerializerOption.DataContractSerializer)
                {
                    XmlQualifiedName xmlQualifiedName = MessageBuilder.XsdDataContractExporter.GetRootElementName(declaredMessageType);
                    if (xmlQualifiedName == null)
                    {
                        xmlQualifiedName = MessageBuilder.XsdDataContractExporter.GetSchemaTypeName(declaredMessageType);
                    }

                    if (!xmlQualifiedName.IsEmpty)
                    {
                        partName      = xmlQualifiedName.Name;
                        partNamespace = xmlQualifiedName.Namespace;
                    }
                    else
                    {
                        // For anonymous type, we assign CLR type name and contract namespace to MessagePartDescription
                        partName      = declaredMessageType.Name;
                        partNamespace = operation.DeclaringContract.Namespace;
                    }
                }
                else
                {
                    XmlTypeMapping xmlTypeMapping = MessageBuilder.XmlReflectionImporter.ImportTypeMapping(declaredMessageType);
                    partName      = xmlTypeMapping.ElementName;
                    partNamespace = xmlTypeMapping.Namespace;
                }

                MessagePartDescription targetPart = null;

                if (isResponse && targetMessage.Body.ReturnValue != null && targetMessage.Body.ReturnValue.Type != TypeHelper.VoidType)
                {
                    if (targetMessage.Body.Parts.Count > 0)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.NotSupportMoreThanOneParametersInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }
                    targetPart = targetMessage.Body.ReturnValue;
                }
                else if (!isResponse)
                {
                    if (targetMessage.Body.WrapperName != null && targetMessage.Body.WrapperName != String.Empty)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.WrapperNotSupportedInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }

                    if (targetMessage.Body.WrapperNamespace != null && targetMessage.Body.WrapperNamespace != String.Empty)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.WrapperNotSupportedInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }

                    if (targetMessage.Body.Parts.Count == 0)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.ParameterNumberMismatch(declaredMessageType.FullName, operation.Name, operation.DeclaringContract.Name)));
                    }
                    else if (targetMessage.Body.Parts.Count > 1)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.MessageContentCannotHaveMoreThanOneParameter(operation.Name, operation.DeclaringContract.Name)));
                    }
                    else
                    {
                        targetPart = targetMessage.Body.Parts[0];
                    }
                }

                if (targetPart != null)
                {
                    if (partName != targetPart.Name)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(partName, "parameter name", targetPart.Name, operation.Name, operation.DeclaringContract.Name)));
                    }
                    if (partNamespace != targetPart.Namespace)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(partNamespace, "parameter namespace", targetPart.Namespace, operation.Name, operation.DeclaringContract.Name)));
                    }
                    if (declaredMessageType != targetPart.Type)
                    {
                        if (declaredMessageType != null)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterTypeMismatch(declaredMessageType.FullName, targetPart.Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                        else
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterTypeMismatch(TypeHelper.VoidType.FullName, targetPart.Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                    }
                    if (targetPart.HasProtectionLevel)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.ProtectionLevelIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
                    }

                    // Multiple and Index do not need to be validate because there is only one part in the message.
                }
            }
        }
Ejemplo n.º 34
0
        public static void AddMessagePartDescription(OperationDescription operation, bool isResponse,
                                                     MessageDescription message, Type type, SerializerOption serializerOption)
        {
            if (type != null)
            {
                string partName;
                string partNamespace;

                if (serializerOption == SerializerOption.DataContractSerializer)
                {
                    XmlQualifiedName xmlQualifiedName = XsdDataContractExporter.GetRootElementName(type);
                    if (xmlQualifiedName == null)
                    {
                        xmlQualifiedName = XsdDataContractExporter.GetSchemaTypeName(type);
                    }

                    if (!xmlQualifiedName.IsEmpty)
                    {
                        partName      = xmlQualifiedName.Name;
                        partNamespace = xmlQualifiedName.Namespace;
                    }
                    else
                    {
                        // For anonymous type, we assign CLR type name and contract namespace to MessagePartDescription
                        partName      = type.Name;
                        partNamespace = operation.DeclaringContract.Namespace;
                    }
                }
                else
                {
                    XmlTypeMapping xmlTypeMapping = XmlReflectionImporter.ImportTypeMapping(type);
                    partName      = xmlTypeMapping.ElementName;
                    partNamespace = xmlTypeMapping.Namespace;
                }

                MessagePartDescription messagePart = new MessagePartDescription(NamingHelper.XmlName(partName), partNamespace)
                {
                    Index = 0,
                    Type  = type

                            // We do not infer MessagePartDescription.ProtectionLevel
                };

                message.Body.Parts.Add(messagePart);
            }

            if (isResponse)
            {
                SetReturnValue(message, operation);
            }
        }
Ejemplo n.º 35
0
        public static void AddOutputMessage(OperationDescription operation, string overridingAction, Type type, SerializerOption serializerOption)
        {
            Fx.Assert(operation.Messages.Count > 0, "Operation does not have input message");
            Fx.Assert(operation.Messages.Count < 2, "Operation already has output message");

            bool isResponse            = true;
            MessageDescription message = MessageBuilder.CreateMessageDescription(
                operation, isResponse, MessageDirection.Output, overridingAction, type, serializerOption);

            operation.Messages.Add(message);
        }