public static void ValidateParametersContent(NativeActivityContext context, MessageDescription targetMessage, IDictionary parameters, OperationDescription targetOperation, bool isResponse) { // The following properties can only be set via message contract. Therefore, we do not need to validate them here. // MessageDescription: Headers, Properties, ProtectionLevel // MessagePartDescription: Namespace, ProtectionLevel, Multiple, Index MessageBodyDescription targetMessageBody = targetMessage.Body; Fx.Assert(targetMessageBody != null, "MessageDescription.Body is never null!"); if (targetMessageBody.WrapperName == null) { Constraint.AddValidationError(context, new ValidationError(SR2.UnwrappedMessageNotSupported(targetOperation.Name, targetOperation.DeclaringContract.Name))); } if (targetMessageBody.WrapperNamespace == null) { Constraint.AddValidationError(context, new ValidationError(SR2.UnwrappedMessageNotSupported(targetOperation.Name, targetOperation.DeclaringContract.Name))); } IDictionaryEnumerator iterator = parameters.GetEnumerator(); int benchmarkIndex = 0; int hitCount = 0; // Return value needs to be treated specially since ReceiveParametersContent does not have return value on the OM. bool targetHasReturnValue = isResponse && targetMessageBody.ReturnValue != null && targetMessageBody.ReturnValue.Type != TypeHelper.VoidType; if (targetHasReturnValue) { if (iterator.MoveNext() && (string)iterator.Key == targetMessageBody.ReturnValue.Name) { Argument argument = (Argument)iterator.Value; if (argument != null && argument.ArgumentType != targetMessageBody.ReturnValue.Type) { Constraint.AddValidationError(context, new ValidationError(SR2.FirstParameterDoesnotMatchTheReturnValue(argument.ArgumentType.FullName, targetMessageBody.ReturnValue.Type.FullName, targetOperation.Name, targetOperation.DeclaringContract.Name))); } hitCount++; } else if (parameters.Contains(targetMessageBody.ReturnValue.Name)) { Constraint.AddValidationError(context, new ValidationError(SR2.ParameterPositionMismatch(targetMessageBody.ReturnValue.Name, targetOperation.Name, targetOperation.DeclaringContract.Name, "0"))); hitCount++; } else { Constraint.AddValidationError(context, new ValidationError(SR2.ReturnValueMissing(targetMessageBody.ReturnValue.Type.FullName, targetOperation.Name, targetOperation.DeclaringContract.Name))); } benchmarkIndex++; } foreach (MessagePartDescription targetPart in targetMessageBody.Parts) { if (iterator.MoveNext() && (string)iterator.Key == targetPart.Name) { Argument argument = (Argument)iterator.Value; if (argument != null && argument.ArgumentType != targetPart.Type) { Constraint.AddValidationError(context, new ValidationError(SR2.ParameterTypeMismatch(targetPart.Name, targetPart.Type.FullName, targetOperation.Name, targetOperation.DeclaringContract.Name))); } hitCount++; } else if (parameters.Contains(targetPart.Name)) { Constraint.AddValidationError(context, new ValidationError(SR2.ParameterPositionMismatch(targetPart.Name, targetOperation.Name, targetOperation.DeclaringContract.Name, benchmarkIndex))); hitCount++; } else { Constraint.AddValidationError(context, new ValidationError(SR2.MissingParameter(targetPart.Name, targetOperation.Name, targetOperation.DeclaringContract.Name))); } benchmarkIndex++; } if (hitCount != parameters.Count) { foreach (string name in parameters.Keys) { XmlQualifiedName qName = new XmlQualifiedName(name, targetOperation.DeclaringContract.Namespace); if (!targetMessageBody.Parts.Contains(qName)) { if (!targetHasReturnValue || targetHasReturnValue && name != targetMessageBody.ReturnValue.Name) { Constraint.AddValidationError(context, new ValidationError(SR2.ExtraParameter(name, targetOperation.Name, targetOperation.DeclaringContract.Name))); } } } } }