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); } }
protected override void Execute(CodeActivityContext context) { object[] emptyArray; if ((this.parameters == null) || (this.parameters.Count == 0)) { emptyArray = System.ServiceModel.Activities.Constants.EmptyArray; } else { emptyArray = new object[this.parameters.Count]; for (int i = 0; i < this.parameters.Count; i++) { emptyArray[i] = this.parameters[i].Get(context); } } if (this.Formatter == null) { OperationDescription operationDescription = ContractInferenceHelper.CreateOneWayOperationDescription(this.Send); this.Formatter = ClientOperationFormatterProvider.GetFormatterFromRuntime(operationDescription); this.Send.OperationDescription = operationDescription; } this.Send.InitializeChannelCacheEnabledSetting(context); System.ServiceModel.Channels.Message message = this.Formatter.SerializeRequest(this.MessageVersion, emptyArray); this.Message.Set(context, message); }
private XName FixServiceContractName(XName serviceContractName) { XName name = serviceContractName ?? this.InternalName; ContractInferenceHelper.ProvideDefaultNamespace(ref name); return(name); }
protected override void Execute(CodeActivityContext context) { object[] inObjects; if (this.parameters == null || this.parameters.Count == 0) { inObjects = Constants.EmptyArray; } else { inObjects = new object[this.parameters.Count]; for (int i = 0; i < this.parameters.Count; i++) { Fx.Assert(this.parameters[i] != null, "Parameter should not be null"); inObjects[i] = this.parameters[i].Get(context); } } // Formatter is cached since it is fixed for each definition of Send if (this.Formatter == null) { OperationDescription operation = ContractInferenceHelper.CreateOneWayOperationDescription(this.Send); this.Formatter = ClientOperationFormatterProvider.GetFormatterFromRuntime(operation); this.Send.OperationDescription = operation; } // Send.ChannelCacheEnabled must be set before we call this.MessageVersion // because this.MessageVersion will cache description and description resolution depends on the value of ChannelCacheEnabled this.Send.InitializeChannelCacheEnabledSetting(context); // MessageVersion is cached for perf reasons since it is fixed for each definition of Send Message outMessage = this.Formatter.SerializeRequest(this.MessageVersion, inObjects); this.Message.Set(context, outMessage); }
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); } }
ServiceEndpoint AddServiceEndpointCore(XName serviceContractName, Binding binding, EndpointAddress address, Uri listenUri = null, string behaviorConfigurationName = null) { if (serviceContractName == null) { throw FxTrace.Exception.ArgumentNull("serviceContractName"); } if (this.inferredContracts == null) { throw FxTrace.Exception.AsError(new InvalidOperationException( SR.ContractNotFoundInAddServiceEndpoint(serviceContractName.LocalName, serviceContractName.NamespaceName))); } ServiceEndpoint serviceEndpoint; ContractDescription description; ContractInferenceHelper.ProvideDefaultNamespace(ref serviceContractName); if (this.inferredContracts.TryGetValue(serviceContractName, out description)) { serviceEndpoint = new ServiceEndpoint(description, binding, address); if (!string.IsNullOrEmpty(behaviorConfigurationName)) { ConfigLoader.LoadChannelBehaviors(behaviorConfigurationName, null, serviceEndpoint.Behaviors); } } else if (serviceContractName == mexContractXName) // Special case for mex endpoint { if (!this.Description.Behaviors.Contains(mexBehaviorType)) { throw FxTrace.Exception.AsError(new InvalidOperationException( SR.ServiceMetadataBehaviorNotFoundForServiceMetadataEndpoint(this.Description.Name))); } serviceEndpoint = new ServiceMetadataEndpoint(binding, address); } else { throw FxTrace.Exception.AsError(new InvalidOperationException( SR.ContractNotFoundInAddServiceEndpoint(serviceContractName.LocalName, serviceContractName.NamespaceName))); } if (listenUri != null) { listenUri = base.MakeAbsoluteUri(listenUri, binding); serviceEndpoint.ListenUri = listenUri; } base.Description.Endpoints.Add(serviceEndpoint); if (TD.ServiceEndpointAddedIsEnabled()) { TD.ServiceEndpointAdded(address.Uri.ToString(), binding.GetType().ToString(), serviceEndpoint.Contract.Name); } return(serviceEndpoint); }
private void CorrectOutMessageForOperationWithFault(Receive receive, OperationInfo operationInfo) { Receive receive2 = operationInfo.Receive; if (((receive != receive2) && receive.HasReply) && (!receive2.HasReply && receive2.HasFault)) { ContractInferenceHelper.CorrectOutMessageForOperation(receive, operationInfo.OperationDescription); operationInfo.Receive = receive; } }
private void CollectCorrelationQueryFromReply(ref Collection <CorrelationQuery> correlationQueries, XName serviceContractName, Activity reply, OperationDescription operation) { SendReply reply2 = reply as SendReply; if (reply2 != null) { CorrelationQuery correlationQuery = ContractInferenceHelper.CreateServerCorrelationQuery(null, reply2.CorrelationInitializers, operation, true); this.CollectCorrelationQuery(ref correlationQueries, serviceContractName, correlationQuery); } }
public static void CorrectOutMessageForOperation(Receive receive, OperationDescription operation) { // Remove the original outMessage Fx.Assert(operation.Messages.Count == 2, "OperationDescription must be two-way for CorrectOutMessageForOperation to be invoked!"); operation.Messages.RemoveAt(1); SendReply sendReply = receive.FollowingReplies[0]; sendReply.InternalContent.InferMessageDescription(operation, sendReply, MessageDirection.Output); ContractInferenceHelper.PostProcessOperation(operation); }
internal override void InferMessageDescription(OperationDescription operation, object owner, MessageDirection direction) { ContractInferenceHelper.CheckForDisposableParameters(operation, this.argumentTypes); string overridingAction = (owner is Receive) ? ((Receive)owner).Action : ((ReceiveReply)owner).Action; if (direction == MessageDirection.Input) { ContractInferenceHelper.AddInputMessage(operation, overridingAction, this.argumentNames, this.argumentTypes); } else { ContractInferenceHelper.AddOutputMessage(operation, overridingAction, this.ArgumentNames, this.ArgumentTypes); } }
InternalSendMessage CreateInternalSend() { InternalSendMessage result = new InternalSendMessage { OwnerDisplayName = this.DisplayName, OperationName = this.OperationName, CorrelatesWith = new InArgument <CorrelationHandle>(new ArgumentValue <CorrelationHandle> { ArgumentName = "CorrelatesWith" }), Endpoint = this.Endpoint, EndpointConfigurationName = this.EndpointConfigurationName, IsOneWay = this.isOneWay, IsSendReply = false, TokenImpersonationLevel = this.TokenImpersonationLevel, ServiceContractName = this.ServiceContractName, Action = this.Action, Parent = this }; if (this.correlationInitializers != null) { foreach (CorrelationInitializer correlation in this.correlationInitializers) { result.CorrelationInitializers.Add(correlation.Clone()); } Collection <CorrelationQuery> internalCorrelationQueryCollection = ContractInferenceHelper.CreateClientCorrelationQueries(null, this.correlationInitializers, this.Action, this.ServiceContractName, this.OperationName, false); Fx.Assert(internalCorrelationQueryCollection.Count <= 1, "Querycollection for send cannot have more than one correlation query"); if (internalCorrelationQueryCollection.Count == 1) { result.CorrelationQuery = internalCorrelationQueryCollection[0]; } } if (this.EndpointAddress != null) { result.EndpointAddress = new InArgument <Uri>(context => ((InArgument <Uri>) this.EndpointAddress).Get(context)); } if (this.lazyCorrelationQueries != null) { foreach (CorrelationQuery correlationQuery in this.lazyCorrelationQueries) { result.ReplyCorrelationQueries.Add(correlationQuery); } } return(result); }
private InternalSendMessage CreateInternalSend() { InternalSendMessage message2 = new InternalSendMessage { OperationName = this.OperationName }; ArgumentValue <CorrelationHandle> expression = new ArgumentValue <CorrelationHandle> { ArgumentName = "CorrelatesWith" }; message2.CorrelatesWith = new InArgument <CorrelationHandle>(expression); message2.Endpoint = this.Endpoint; message2.EndpointConfigurationName = this.EndpointConfigurationName; message2.IsOneWay = this.isOneWay; message2.IsSendReply = false; message2.TokenImpersonationLevel = this.TokenImpersonationLevel; message2.ServiceContractName = this.ServiceContractName; message2.Action = this.Action; message2.Parent = this; InternalSendMessage message = message2; if (this.correlationInitializers != null) { foreach (CorrelationInitializer initializer in this.correlationInitializers) { message.CorrelationInitializers.Add(initializer.Clone()); } Collection <CorrelationQuery> collection = ContractInferenceHelper.CreateClientCorrelationQueries(null, this.correlationInitializers, this.Action, this.ServiceContractName, this.OperationName, false); if (collection.Count == 1) { message.CorrelationQuery = collection[0]; } } if (this.EndpointAddress != null) { message.EndpointAddress = new InArgument <Uri>(context => this.EndpointAddress.Get(context)); } if (this.lazyCorrelationQueries != null) { foreach (CorrelationQuery query in this.lazyCorrelationQueries) { message.ReplyCorrelationQueries.Add(query); } } return(message); }
protected override void CacheMetadata(ActivityMetadata metadata) { if (this.Request == null) { metadata.AddValidationError(SR.ReceiveReplyRequestCannotBeNull(this.DisplayName)); } else { // Need to validate Send.ServiceContractName and Send.OperationName here so that we can proceed with contract inference if (this.Request.ServiceContractName == null) { string errorOperationName = ContractValidationHelper.GetErrorMessageOperationName(this.Request.OperationName); metadata.AddValidationError(SR.MissingServiceContractName(this.Request.DisplayName, errorOperationName)); } if (string.IsNullOrEmpty(this.Request.OperationName)) { metadata.AddValidationError(SR.MissingOperationName(this.Request.DisplayName)); } } // validate Correlation Initializers MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, this.DisplayName, (this.Request != null ? this.Request.OperationName : String.Empty)); // Validate Content string operationName = this.Request != null ? this.Request.OperationName : null; this.InternalContent.CacheMetadata(metadata, this, operationName); if (this.correlationInitializers != null) { for (int i = 0; i < this.correlationInitializers.Count; i++) { CorrelationInitializer initializer = this.correlationInitializers[i]; initializer.ArgumentName = Constants.Parameter + i; RuntimeArgument initializerArgument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In); metadata.Bind(initializer.CorrelationHandle, initializerArgument); metadata.AddArgument(initializerArgument); } } if (!metadata.HasViolations) { this.internalReceive = CreateInternalReceive(); InArgument <CorrelationHandle> requestReplyHandleFromSend = GetReplyHandleFromSend(); if (requestReplyHandleFromSend != null) { InArgument <CorrelationHandle> resultCorrelatesWith = MessagingActivityHelper.CreateReplyCorrelatesWith(requestReplyHandleFromSend); RuntimeArgument resultCorrelatesWithArgument = new RuntimeArgument("ResultCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In); metadata.Bind(resultCorrelatesWith, resultCorrelatesWithArgument); metadata.AddArgument(resultCorrelatesWithArgument); this.internalReceive.CorrelatesWith = (InArgument <CorrelationHandle>)InArgument.CreateReference(resultCorrelatesWith, "ResultCorrelatesWith"); } this.InternalContent.ConfigureInternalReceiveReply(this.internalReceive, out this.responseFormatter); if (this.InternalContent is ReceiveMessageContent && MessageBuilder.IsMessageContract(((ReceiveMessageContent)this.InternalContent).InternalDeclaredMessageType)) { this.Request.OperationUsesMessageContract = true; } OperationDescription operation = ContractInferenceHelper.CreateTwoWayOperationDescription(this.Request, this); this.Request.OperationDescription = operation; if (this.responseFormatter != null) { IClientMessageFormatter formatter = ClientOperationFormatterProvider.GetFormatterFromRuntime(operation); this.Request.SetFormatter(formatter); this.responseFormatter.Formatter = formatter; // int index = 0; Type[] faultTypes = new Type[operation.KnownTypes.Count]; foreach (Type type in operation.KnownTypes) { faultTypes[index] = type; index++; } this.responseFormatter.FaultFormatter = new FaultFormatter(faultTypes); } // Add CorrelationQuery to the Send->ReplyCorrelation, we validate that the same query is not added multiple times if (this.correlationInitializers != null && this.correlationInitializers.Count > 0) { Collection <CorrelationQuery> internalCorrelationQueryCollection = ContractInferenceHelper.CreateClientCorrelationQueries(null, this.correlationInitializers, this.Action, this.Request.ServiceContractName, this.Request.OperationName, true); foreach (CorrelationQuery query in internalCorrelationQueryCollection) { this.Request.SetReplyCorrelationQuery(query); } } } else { this.internalReceive = null; this.responseFormatter = null; } // We don't have any imported children despite referencing the Request metadata.SetImportedChildrenCollection(new Collection <Activity>()); }
protected override void CacheMetadata(ActivityMetadata metadata) { if (this.Request == null) { metadata.AddValidationError(System.ServiceModel.Activities.SR.ReceiveReplyRequestCannotBeNull(base.DisplayName)); } else { if (this.Request.ServiceContractName == null) { string errorMessageOperationName = ContractValidationHelper.GetErrorMessageOperationName(this.Request.OperationName); metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingServiceContractName(this.Request.DisplayName, errorMessageOperationName)); } if (string.IsNullOrEmpty(this.Request.OperationName)) { metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingOperationName(this.Request.DisplayName)); } } MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, base.DisplayName, (this.Request != null) ? this.Request.OperationName : string.Empty); string operationName = (this.Request != null) ? this.Request.OperationName : null; this.InternalContent.CacheMetadata(metadata, this, operationName); if (this.correlationInitializers != null) { for (int i = 0; i < this.correlationInitializers.Count; i++) { CorrelationInitializer initializer = this.correlationInitializers[i]; initializer.ArgumentName = "Parameter" + i; RuntimeArgument argument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In); metadata.Bind(initializer.CorrelationHandle, argument); metadata.AddArgument(argument); } } if (!metadata.HasViolations) { this.internalReceive = this.CreateInternalReceive(); InArgument <CorrelationHandle> replyHandleFromSend = this.GetReplyHandleFromSend(); if (replyHandleFromSend != null) { InArgument <CorrelationHandle> binding = MessagingActivityHelper.CreateReplyCorrelatesWith(replyHandleFromSend); RuntimeArgument argument4 = new RuntimeArgument("ResultCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In); metadata.Bind(binding, argument4); metadata.AddArgument(argument4); this.internalReceive.CorrelatesWith = (InArgument <CorrelationHandle>)InArgument.CreateReference(binding, "ResultCorrelatesWith"); } this.InternalContent.ConfigureInternalReceiveReply(this.internalReceive, out this.responseFormatter); if ((this.InternalContent is ReceiveMessageContent) && MessageBuilder.IsMessageContract(((ReceiveMessageContent)this.InternalContent).InternalDeclaredMessageType)) { this.Request.OperationUsesMessageContract = true; } OperationDescription operationDescription = ContractInferenceHelper.CreateTwoWayOperationDescription(this.Request, this); this.Request.OperationDescription = operationDescription; if (this.responseFormatter != null) { IClientMessageFormatter formatterFromRuntime = ClientOperationFormatterProvider.GetFormatterFromRuntime(operationDescription); this.Request.SetFormatter(formatterFromRuntime); this.responseFormatter.Formatter = formatterFromRuntime; int index = 0; Type[] detailTypes = new Type[operationDescription.KnownTypes.Count]; foreach (Type type in operationDescription.KnownTypes) { detailTypes[index] = type; index++; } this.responseFormatter.FaultFormatter = new FaultFormatter(detailTypes); } if ((this.correlationInitializers != null) && (this.correlationInitializers.Count > 0)) { foreach (CorrelationQuery query in ContractInferenceHelper.CreateClientCorrelationQueries(null, this.correlationInitializers, this.Action, this.Request.ServiceContractName, this.Request.OperationName, true)) { this.Request.SetReplyCorrelationQuery(query); } } } else { this.internalReceive = null; this.responseFormatter = null; } metadata.SetImportedChildrenCollection(new Collection <Activity>()); }
internal IDictionary <XName, ContractDescription> GetContractDescriptions() { if (this.cachedInferredContracts == null) { this.WalkActivityTree(); this.correlationQueryByContract = new Dictionary <XName, Collection <CorrelationQuery> >(); IDictionary <XName, ContractDescription> dictionary = new Dictionary <XName, ContractDescription>(); IDictionary <ContractAndOperationNameTuple, OperationInfo> dictionary2 = new Dictionary <ContractAndOperationNameTuple, OperationInfo>(); foreach (Receive receive in this.knownServiceActivities) { OperationInfo info; XName serviceContractXName = this.FixServiceContractName(receive.ServiceContractName); ContractAndOperationNameTuple key = new ContractAndOperationNameTuple(serviceContractXName, receive.OperationName); if (dictionary2.TryGetValue(key, out info)) { ContractValidationHelper.ValidateReceiveWithReceive(receive, info.Receive); } else { ContractDescription description; if (!dictionary.TryGetValue(serviceContractXName, out description)) { description = new ContractDescription(serviceContractXName.LocalName, serviceContractXName.NamespaceName) { ConfigurationName = serviceContractXName.LocalName }; dictionary.Add(serviceContractXName, description); } OperationDescription item = ContractInferenceHelper.CreateOperationDescription(receive, description); description.Operations.Add(item); info = new OperationInfo(receive, item); dictionary2.Add(key, info); } this.CorrectOutMessageForOperationWithFault(receive, info); ContractInferenceHelper.UpdateIsOneWayFlag(receive, info.OperationDescription); ContractInferenceHelper.AddFaultDescription(receive, info.OperationDescription); ContractInferenceHelper.AddKnownTypesToOperation(receive, info.OperationDescription); ContractInferenceHelper.AddReceiveToFormatterBehavior(receive, info.OperationDescription); Collection <CorrelationQuery> queries = null; if (receive.HasCorrelatesOn || receive.HasCorrelationInitializers) { MessageQuerySet select = receive.HasCorrelatesOn ? receive.CorrelatesOn : null; CorrelationQuery correlationQuery = ContractInferenceHelper.CreateServerCorrelationQuery(select, receive.CorrelationInitializers, info.OperationDescription, false); this.CollectCorrelationQuery(ref queries, serviceContractXName, correlationQuery); } if (receive.HasReply) { foreach (SendReply reply in receive.FollowingReplies) { ReceiveAndReplyTuple tuple2 = new ReceiveAndReplyTuple(receive, reply); this.receiveAndReplyPairs.Remove(tuple2); this.CollectCorrelationQueryFromReply(ref queries, serviceContractXName, reply, info.OperationDescription); reply.SetContractName(serviceContractXName); } } if (receive.HasFault) { foreach (Activity activity in receive.FollowingFaults) { ReceiveAndReplyTuple tuple3 = new ReceiveAndReplyTuple(receive, activity); this.receiveAndReplyPairs.Remove(tuple3); this.CollectCorrelationQueryFromReply(ref queries, serviceContractXName, activity, info.OperationDescription); } } } if (this.receiveAndReplyPairs.Count != 0) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.DanglingReceive)); } if (System.ServiceModel.Activities.TD.InferredContractDescriptionIsEnabled()) { foreach (ContractDescription description3 in dictionary.Values) { System.ServiceModel.Activities.TD.InferredContractDescription(description3.Name, description3.Namespace); if (System.ServiceModel.Activities.TD.InferredOperationDescriptionIsEnabled()) { foreach (OperationDescription description4 in description3.Operations) { System.ServiceModel.Activities.TD.InferredOperationDescription(description4.Name, description3.Name, description4.IsOneWay.ToString()); } } } } this.cachedInferredContracts = dictionary; } return(this.cachedInferredContracts); }