Ejemplo n.º 1
0
 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);
 }
        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);
        }
Ejemplo n.º 3
0
        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>());
        }
Ejemplo n.º 4
0
        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>());
        }