Beispiel #1
0
        object IOperationInvoker.Invoke(object instance, object[] inputs, out object[] outputs)
        {
            outputs = new object[0];
            object  retVal  = null;
            Invoker invoker = null;

            // set incoming objects in the CallContext
            LCC.SetDataContract(OperationContext.Current.IncomingMessageHeaders, this._callContextActors);
            LogicalWorkflowContext lwc = LCC.LogicalWorkflowContext;

            // check the workflowId
            Guid workflowInstanceId = lwc.GetAndClearWorkflowId();
            bool bGetWorkflowById   = !workflowInstanceId.Equals(Guid.Empty);

            // options for workflow type
            if (this._workflowType == null)
            {
                string endpointUri = string.Concat(instance.GetType().FullName, ".", this._description.SyncMethod.Name);
                this._workflowType = RemotingServices.GetServerTypeForUri(endpointUri);
            }
            if (!bGetWorkflowById && this._workflowType == null)
            {
                // throw exception or perform some pre-processing
                retVal = this._innerOperationInvoker.Invoke(instance, inputs, out outputs);

                // done (no workflow invoked)
                return(retVal);
            }

            // create message operation
            MethodMessage message = new MethodMessage(this._description.SyncMethod, inputs, null);

            // workflow invoker options (statefull or stateless)
            if (bGetWorkflowById)
            {
                invoker = WorkflowInvoker.Create(workflowInstanceId);
            }
            else
            {
                invoker = WorkflowInvoker.Create(this._workflowType, lwc.WorkflowInitData);
            }

            // send message to the workflow queue
            invoker.SendMessage(message);

            // response
            if (!this._description.IsOneWay)
            {
                invoker.WaitForResponse(this.ResponseTime);
                retVal = invoker.GetResponse <object>();
            }

            // done
            return(retVal);
        }