private static void ValidateReceiveWithReceive(ReceiveMessageContent receive1, ReceiveMessageContent receive2, string receiveOperationName) { if (receive1.InternalDeclaredMessageType != receive2.InternalDeclaredMessageType) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.TwoReceivesWithSameNameButDifferentValueType(receiveOperationName))); } }
static void ValidateReceiveWithReceive(ReceiveMessageContent receive1, ReceiveMessageContent receive2, string receiveOperationName) { Fx.Assert(receive1 != null && receive2 != null, "Validation argument cannot be null!"); if (receive1.InternalDeclaredMessageType != receive2.InternalDeclaredMessageType) { throw FxTrace.Exception.AsError(new ValidationException(SR2.TwoReceivesWithSameNameButDifferentValueType(receiveOperationName))); } }
public static void ValidateReceiveWithReceive(Receive receive1, Receive receive2) { Fx.Assert(receive1 != null && receive2 != null, "Validation argument cannot be null!"); Fx.Assert(receive1.OperationName != null, "OperationName cannot be null in Receive"); string receiveOperationName = receive1.OperationName; if (receive1.Action != receive2.Action) { throw FxTrace.Exception.AsError(new ValidationException(SR2.TwoReceivesWithSameNameButDifferentAction(receiveOperationName))); } if (receive1.InternalContent is ReceiveMessageContent && receive2.InternalContent is ReceiveMessageContent) { ReceiveMessageContent receiveMessage1 = receive1.InternalContent as ReceiveMessageContent; ReceiveMessageContent receiveMessage2 = receive2.InternalContent as ReceiveMessageContent; ValidateReceiveWithReceive(receiveMessage1, receiveMessage2, receiveOperationName); } else if (receive1.InternalContent is ReceiveParametersContent && receive2.InternalContent is ReceiveParametersContent) { ReceiveParametersContent receiveParameters1 = receive1.InternalContent as ReceiveParametersContent; ReceiveParametersContent receiveParameters2 = receive2.InternalContent as ReceiveParametersContent; ValidateReceiveParametersWithReceiveParameters(receiveParameters1, receiveParameters2, receiveOperationName); } else { throw FxTrace.Exception.AsError(new ValidationException(SR2.ReceiveAndReceiveParametersHaveSameName(receiveOperationName))); } if (receive1.HasReply && receive2.HasReply) { ValidateSendReplyWithSendReply(receive1.FollowingReplies[0], receive2.FollowingReplies[0]); } else if ((receive1.HasReply || receive1.HasFault) != (receive2.HasReply || receive2.HasFault)) { throw FxTrace.Exception.AsError(new ValidationException(SR2.TwoReceivesWithSameNameButDifferentIsOneWay(receiveOperationName))); } if ((receive1.InternalReceive.AdditionalData.IsInsideTransactedReceiveScope != receive2.InternalReceive.AdditionalData.IsInsideTransactedReceiveScope) || (receive1.InternalReceive.AdditionalData.IsFirstReceiveOfTransactedReceiveScopeTree != receive2.InternalReceive.AdditionalData.IsFirstReceiveOfTransactedReceiveScopeTree)) { throw FxTrace.Exception.AsError(new ValidationException(SR2.TwoReceivesWithSameNameButDifferentTxProperties(receiveOperationName))); } }
bool IsInvalidContentChangeFrom(ReceiveContent originalContent) { ReceiveMessageContent newMsgContent = this.InternalContent as ReceiveMessageContent; ReceiveMessageContent originalMsgContent = originalContent as ReceiveMessageContent; if (newMsgContent != null && newMsgContent.InternalDeclaredMessageType == MessageDescription.TypeOfUntypedMessage) { if (originalMsgContent == null || originalMsgContent.InternalDeclaredMessageType != MessageDescription.TypeOfUntypedMessage) { return(true); } } else if (originalMsgContent != null && originalMsgContent.InternalDeclaredMessageType == MessageDescription.TypeOfUntypedMessage) { return(true); } return(false); }
public static void ValidateReceiveWithReceive(Receive receive1, Receive receive2) { string operationName = receive1.OperationName; if (receive1.Action != receive2.Action) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.TwoReceivesWithSameNameButDifferentAction(operationName))); } if ((receive1.InternalContent is ReceiveMessageContent) && (receive2.InternalContent is ReceiveMessageContent)) { ReceiveMessageContent internalContent = receive1.InternalContent as ReceiveMessageContent; ReceiveMessageContent content2 = receive2.InternalContent as ReceiveMessageContent; ValidateReceiveWithReceive(internalContent, content2, operationName); } else { if (!(receive1.InternalContent is ReceiveParametersContent) || !(receive2.InternalContent is ReceiveParametersContent)) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.ReceiveAndReceiveParametersHaveSameName(operationName))); } ReceiveParametersContent content3 = receive1.InternalContent as ReceiveParametersContent; ReceiveParametersContent content4 = receive2.InternalContent as ReceiveParametersContent; ValidateReceiveParametersWithReceiveParameters(content3, content4, operationName); } if (receive1.HasReply && receive2.HasReply) { ValidateSendReplyWithSendReply(receive1.FollowingReplies[0], receive2.FollowingReplies[0]); } else if ((receive1.HasReply || receive1.HasFault) != (receive2.HasReply || receive2.HasFault)) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.TwoReceivesWithSameNameButDifferentIsOneWay(operationName))); } if ((receive1.InternalReceive.AdditionalData.IsInsideTransactedReceiveScope != receive2.InternalReceive.AdditionalData.IsInsideTransactedReceiveScope) || (receive1.InternalReceive.AdditionalData.IsFirstReceiveOfTransactedReceiveScopeTree != receive2.InternalReceive.AdditionalData.IsFirstReceiveOfTransactedReceiveScopeTree)) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.TwoReceivesWithSameNameButDifferentTxProperties(operationName))); } }
public static Receive FromOperationDescription(OperationDescription operation) { if (operation == null) { throw FxTrace.Exception.ArgumentNull("operation", "OperationDescription should not be null"); } MessageDescription message; Receive receiveActivity = new Receive(); receiveActivity.ServiceContractName = XName.Get(operation.DeclaringContract.Name, operation.DeclaringContract.Namespace); receiveActivity.OperationName = operation.Name; receiveActivity.DisplayName = operation.Name + "Receive"; receiveActivity.ProtectionLevel = operation.ProtectionLevel; if (operation.Messages != null && operation.Messages.Count > 0) { receiveActivity.Action = operation.Messages[0].Action; } Collection<Type> knownTypes = operation.KnownTypes; if (knownTypes != null) { foreach (Type knownType in knownTypes) { receiveActivity.KnownTypes.Add(knownType); } } // Set SerializerOption if (operation.Behaviors.Contains(typeof(XmlSerializerOperationBehavior))) { receiveActivity.SerializerOption = SerializerOption.XmlSerializer; } else { receiveActivity.SerializerOption = SerializerOption.DataContractSerializer; } bool contentIsParameter = false; bool noReceiveMessageContent = false; message = operation.Messages[0]; // MessageType is null indicating it is not typed message contract if (message.MessageType == null) { if (message.Body.Parts != null) { if (message.Body.Parts.Count != 0) { foreach (MessagePartDescription messagePart in message.Body.Parts) { if (messagePart.Index > 0) { contentIsParameter = true; break; } // Indicating it is a untyped message contract if (!messagePart.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message))) { contentIsParameter = true; } } } else { noReceiveMessageContent = true; } } else { noReceiveMessageContent = true; } } if (!noReceiveMessageContent) { if (contentIsParameter) { ReceiveParametersContent content = new ReceiveParametersContent(); if (message.Direction == MessageDirection.Input && message.Body.Parts != null) { foreach (MessagePartDescription messagePart in message.Body.Parts) { Argument outArgument = OutArgument.Create(messagePart.Type, ArgumentDirection.Out); content.Parameters.Add(messagePart.Name, (OutArgument)(outArgument)); } } receiveActivity.Content = content; } else { ReceiveMessageContent content = new ReceiveMessageContent(); if (message.Direction == MessageDirection.Input) { if (message.MessageType != null) { content.DeclaredMessageType = message.MessageType; } else { content.DeclaredMessageType = message.Body.Parts[0].Type; } Argument outArgument = OutArgument.Create(content.DeclaredMessageType, ArgumentDirection.Out); content.Message = (OutArgument)outArgument; } receiveActivity.Content = content; } } else { if ((message.Body.ReturnValue != null && message.Body.ReturnValue.Type.IsDefined(typeof(MessageContractAttribute), false)) || (message.Body.ReturnValue != null && message.Body.ReturnValue.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))) { receiveActivity.Content = new ReceiveMessageContent(); } else if (operation.Messages.Count > 1) { if (operation.Messages[1].MessageType != null || operation.Messages[1].Body.ReturnValue.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message))) { receiveActivity.Content = new ReceiveMessageContent(); } else { receiveActivity.Content = new ReceiveParametersContent(); } } else { receiveActivity.Content = new ReceiveParametersContent(); } } return receiveActivity; }
public static Receive FromOperationDescription(OperationDescription operation) { if (operation == null) { throw FxTrace.Exception.ArgumentNull("operation", "OperationDescription should not be null"); } MessageDescription message; Receive receiveActivity = new Receive(); receiveActivity.ServiceContractName = XName.Get(operation.DeclaringContract.Name, operation.DeclaringContract.Namespace); receiveActivity.OperationName = operation.Name; receiveActivity.DisplayName = operation.Name + "Receive"; receiveActivity.ProtectionLevel = operation.ProtectionLevel; if (operation.Messages != null && operation.Messages.Count > 0) { receiveActivity.Action = operation.Messages[0].Action; } Collection <Type> knownTypes = operation.KnownTypes; if (knownTypes != null) { foreach (Type knownType in knownTypes) { receiveActivity.KnownTypes.Add(knownType); } } // Set SerializerOption if (operation.Behaviors.Contains(typeof(XmlSerializerOperationBehavior))) { receiveActivity.SerializerOption = SerializerOption.XmlSerializer; } else { receiveActivity.SerializerOption = SerializerOption.DataContractSerializer; } bool contentIsParameter = false; bool noReceiveMessageContent = false; message = operation.Messages[0]; // MessageType is null indicating it is not typed message contract if (message.MessageType == null) { if (message.Body.Parts != null) { if (message.Body.Parts.Count != 0) { foreach (MessagePartDescription messagePart in message.Body.Parts) { if (messagePart.Index > 0) { contentIsParameter = true; break; } // Indicating it is a untyped message contract if (!messagePart.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message))) { contentIsParameter = true; } } } else { noReceiveMessageContent = true; } } else { noReceiveMessageContent = true; } } if (!noReceiveMessageContent) { if (contentIsParameter) { ReceiveParametersContent content = new ReceiveParametersContent(); if (message.Direction == MessageDirection.Input && message.Body.Parts != null) { foreach (MessagePartDescription messagePart in message.Body.Parts) { Argument outArgument = OutArgument.Create(messagePart.Type, ArgumentDirection.Out); content.Parameters.Add(messagePart.Name, (OutArgument)(outArgument)); } } receiveActivity.Content = content; } else { ReceiveMessageContent content = new ReceiveMessageContent(); if (message.Direction == MessageDirection.Input) { if (message.MessageType != null) { content.DeclaredMessageType = message.MessageType; } else { content.DeclaredMessageType = message.Body.Parts[0].Type; } Argument outArgument = OutArgument.Create(content.DeclaredMessageType, ArgumentDirection.Out); content.Message = (OutArgument)outArgument; } receiveActivity.Content = content; } } else { if ((message.Body.ReturnValue != null && message.Body.ReturnValue.Type.IsDefined(typeof(MessageContractAttribute), false)) || (message.Body.ReturnValue != null && message.Body.ReturnValue.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))) { receiveActivity.Content = new ReceiveMessageContent(); } else if (operation.Messages.Count > 1) { if (operation.Messages[1].MessageType != null || operation.Messages[1].Body.ReturnValue.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message))) { receiveActivity.Content = new ReceiveMessageContent(); } else { receiveActivity.Content = new ReceiveParametersContent(); } } else { receiveActivity.Content = new ReceiveParametersContent(); } } return(receiveActivity); }