Ejemplo n.º 1
0
 public static MessageDescription CreateEmptyMessageDescription(OperationDescription operation, bool isResponse, MessageDirection direction, string overridingAction)
 {
     return(new MessageDescription(overridingAction ?? NamingHelper.GetMessageAction(operation, isResponse), direction)
     {
         Body = { WrapperName = null, WrapperNamespace = null }
     });
 }
Ejemplo n.º 2
0
        public static MessageDescription CreateFromMessageContract(OperationDescription operation, bool isResponse, MessageDirection direction, string overridingAction, Type messageContractType)
        {
            string     action = overridingAction ?? NamingHelper.GetMessageAction(operation, isResponse);
            TypeLoader loader = new TypeLoader();

            return(loader.CreateTypedMessageDescription(messageContractType, null, null, operation.DeclaringContract.Namespace, action, direction));
        }
 public static void EnsureTransactionFlowOnContract(ref ServiceEndpoint serviceEndpoint, XName serviceContractName, string operationName, string action, ProtectionLevel?protectionLevel)
 {
     if (serviceEndpoint.Contract.ContractType == null)
     {
         serviceEndpoint.Contract.Operations[0].Behaviors.Add(new TransactionFlowAttribute(TransactionFlowOption.Allowed));
     }
     else
     {
         ContractDescription  declaringContract = null;
         OperationDescription operation         = null;
         MessageDescription   item         = null;
         MessageDescription   description4 = null;
         System.Type          type         = typeof(IRequestChannel);
         ProvideDefaultNamespace(ref serviceContractName);
         declaringContract = new ContractDescription(serviceContractName.LocalName, serviceContractName.NamespaceName)
         {
             ContractType = type,
             SessionMode  = SessionMode.Allowed
         };
         operation = new OperationDescription(operationName, declaringContract)
         {
             Behaviors = { new TransactionFlowAttribute(TransactionFlowOption.Allowed) }
         };
         string messageAction = null;
         string str2          = null;
         if (string.IsNullOrEmpty(action))
         {
             messageAction = NamingHelper.GetMessageAction(operation, false);
             str2          = NamingHelper.GetMessageAction(operation, true);
         }
         else
         {
             messageAction = action;
             str2          = action + "Response";
         }
         item         = new MessageDescription(messageAction, MessageDirection.Input);
         description4 = new MessageDescription(str2, MessageDirection.Output);
         operation.Messages.Add(item);
         operation.Messages.Add(description4);
         if (protectionLevel.HasValue)
         {
             operation.ProtectionLevel = protectionLevel.Value;
         }
         declaringContract.Operations.Add(operation);
         Uri             listenUri = serviceEndpoint.ListenUri;
         ServiceEndpoint endpoint  = new ServiceEndpoint(declaringContract)
         {
             Binding = serviceEndpoint.Binding,
             Address = serviceEndpoint.Address,
             Name    = serviceEndpoint.Name
         };
         serviceEndpoint = endpoint;
         if (listenUri != null)
         {
             serviceEndpoint.ListenUri = listenUri;
         }
     }
 }
 public static void ValidateAction(NativeActivityContext context, MessageDescription targetMessage, string overridingAction,
                                   OperationDescription targetOperation, bool isResponse)
 {
     if (overridingAction == null && targetMessage.Action != NamingHelper.GetMessageAction(targetOperation, isResponse) ||
         overridingAction != null && overridingAction != targetMessage.Action)
     {
         Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(overridingAction, "Action", targetMessage.Action, targetOperation.Name, targetOperation.DeclaringContract.Name)));
     }
 }
Ejemplo n.º 5
0
        public static MessageDescription CreateEmptyMessageDescription(OperationDescription operation, bool isResponse,
                                                                       MessageDirection direction, string overridingAction)
        {
            string             action = overridingAction ?? NamingHelper.GetMessageAction(operation, isResponse);
            MessageDescription result = new MessageDescription(action, direction);

            // Clear message wrapper
            result.Body.WrapperName      = null;
            result.Body.WrapperNamespace = null;

            return(result);
        }
Ejemplo n.º 6
0
        public static FaultDescription CreateFaultDescription(OperationDescription operation, Type faultType, string overridingAction)
        {
            string           name        = NamingHelper.TypeName(faultType) + "Fault";
            string           action      = overridingAction ?? (NamingHelper.GetMessageAction(operation, false) + name);
            FaultDescription description = new FaultDescription(action)
            {
                Namespace  = operation.DeclaringContract.Namespace,
                DetailType = faultType
            };

            description.SetNameOnly(new System.ServiceModel.Description.XmlName(name));
            return(description);
        }
Ejemplo n.º 7
0
        public static FaultDescription CreateFaultDescription(OperationDescription operation, Type faultType, string overridingAction)
        {
            string           name   = NamingHelper.TypeName(faultType) + TypeLoader.FaultSuffix;
            string           action = overridingAction ?? NamingHelper.GetMessageAction(operation, false) + name;
            FaultDescription result = new FaultDescription(action)
            {
                Namespace  = operation.DeclaringContract.Namespace,
                DetailType = faultType
            };

            result.SetNameOnly(new XmlName(name));
            return(result);
        }
Ejemplo n.º 8
0
        private OperationDescription CreateOperationDescription(ContractDescription contract, System.Reflection.MethodInfo methodInfo, ComContractElement config, bool allowReferences)
        {
            System.ServiceModel.Description.XmlName methodName      = new System.ServiceModel.Description.XmlName(ServiceReflector.GetLogicalName(methodInfo));
            System.ServiceModel.Description.XmlName returnValueName = TypeLoader.GetReturnValueName(methodName);
            if (ServiceReflector.IsBegin(methodInfo))
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NoAsyncOperationsAllowed());
            }
            if (contract.Operations.FindAll(methodName.EncodedName).Count != 0)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.DuplicateOperation());
            }
            OperationDescription description = new OperationDescription(methodName.EncodedName, contract)
            {
                SyncMethod    = methodInfo,
                IsInitiating  = true,
                IsTerminating = false
            };

            description.KnownTypes.Add(typeof(Array));
            description.KnownTypes.Add(typeof(DBNull));
            description.KnownTypes.Add(typeof(CurrencyWrapper));
            description.KnownTypes.Add(typeof(ErrorWrapper));
            if (allowReferences)
            {
                description.KnownTypes.Add(typeof(PersistStreamTypeWrapper));
            }
            foreach (ComUdtElement element in config.UserDefinedTypes)
            {
                Type type;
                Guid typeLibId = Fx.CreateGuid(element.TypeLibID);
                TypeCacheManager.Provider.FindOrCreateType(typeLibId, element.TypeLibVersion, Fx.CreateGuid(element.TypeDefID), out type, false);
                this.info.AddUdt(type, typeLibId);
                description.KnownTypes.Add(type);
            }
            string             ns           = contract.Namespace;
            XmlQualifiedName   contractName = new XmlQualifiedName(contract.Name, ns);
            string             action       = NamingHelper.GetMessageAction(contractName, methodName.DecodedName, null, false);
            string             str3         = NamingHelper.GetMessageAction(contractName, methodName.DecodedName, null, true);
            MessageDescription item         = this.CreateIncomingMessageDescription(contract, methodInfo, ns, action, allowReferences);
            MessageDescription description3 = this.CreateOutgoingMessageDescription(contract, methodInfo, returnValueName, ns, str3, allowReferences);

            description.Messages.Add(item);
            description.Messages.Add(description3);
            return(description);
        }
        public static void ValidateFault(NativeActivityContext context, OperationDescription targetOperation, string overridingAction, Type faultType)
        {
            bool faultTypeExistOnContract = false;

            for (int index = 0; index < targetOperation.Faults.Count; index++)
            {
                FaultDescription targetFault = targetOperation.Faults[index];

                if (targetFault.DetailType == faultType)
                {
                    string name   = NamingHelper.TypeName(faultType) + TypeLoader.FaultSuffix;
                    string action = overridingAction ?? NamingHelper.GetMessageAction(targetOperation, false) + name;

                    if (targetFault.Action != action)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(action, "Fault Action", targetFault.Action, targetOperation.Name, targetOperation.DeclaringContract.Name)));
                    }
                    if (targetFault.Name != NamingHelper.XmlName(name))
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(NamingHelper.XmlName(name), "Fault Name", targetFault.Name, targetOperation.Name, targetOperation.DeclaringContract.Name)));
                    }
                    if (targetFault.Namespace != targetOperation.DeclaringContract.Namespace)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(targetOperation.DeclaringContract.Namespace, "Fault Namespace", targetFault.Namespace, targetOperation.Name, targetOperation.DeclaringContract.Name)));
                    }
                    if (targetFault.HasProtectionLevel)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.ProtectionLevelNotSupported(targetOperation.Name, targetOperation.DeclaringContract.Name)));
                    }

                    // TypeLoader guarantees that fault types are unique in the Faults collection.
                    faultTypeExistOnContract = true;
                    break;
                }
            }

            // It is OK to have fewer fault types than defined on the contract.
            // But we do not allow workflow to define more fault types than specified on the contract.
            if (!faultTypeExistOnContract)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.FaultTypeMismatch(faultType.FullName, targetOperation.Name, targetOperation.DeclaringContract.Name)));
            }
        }
Ejemplo n.º 10
0
        // this method generates the correlationQuery for client side send and receiveReply
        public static Collection <CorrelationQuery> CreateClientCorrelationQueries(MessageQuerySet select, Collection <CorrelationInitializer> correlationInitializers,
                                                                                   string overridingAction, XName serviceContractName, string operationName, bool isResponse)
        {
            Fx.Assert(serviceContractName != null && operationName != null, "Argument cannot be null!");

            Collection <CorrelationQuery> queryCollection = new Collection <CorrelationQuery>();
            CorrelationQuery correlationQuery             = CreateCorrelationQueryCore(select, correlationInitializers);

            if (correlationQuery != null)
            {
                if (overridingAction != null)
                {
                    correlationQuery.Where = new CorrelationActionMessageFilter {
                        Action = overridingAction
                    };
                }
                else
                {
                    ProvideDefaultNamespace(ref serviceContractName);
                    string defaultAction = NamingHelper.GetMessageAction(new XmlQualifiedName(serviceContractName.LocalName, serviceContractName.NamespaceName),
                                                                         operationName, null, isResponse);

                    correlationQuery.Where = new CorrelationActionMessageFilter {
                        Action = defaultAction
                    };
                }

                queryCollection.Add(correlationQuery);

                if (isResponse)
                {
                    // we need an additional query with empty action to support soap1.1 reply cases
                    CorrelationQuery noActionQuery = correlationQuery.Clone();
                    noActionQuery.Where = new CorrelationActionMessageFilter {
                        Action = String.Empty
                    };
                    queryCollection.Add(noActionQuery);
                }
            }

            return(queryCollection);
        }
        public static Collection <CorrelationQuery> CreateClientCorrelationQueries(MessageQuerySet select, Collection <CorrelationInitializer> correlationInitializers, string overridingAction, XName serviceContractName, string operationName, bool isResponse)
        {
            Collection <CorrelationQuery> collection = new Collection <CorrelationQuery>();
            CorrelationQuery item = CreateCorrelationQueryCore(select, correlationInitializers);

            if (item != null)
            {
                if (overridingAction != null)
                {
                    CorrelationActionMessageFilter filter = new CorrelationActionMessageFilter {
                        Action = overridingAction
                    };
                    item.Where = filter;
                }
                else
                {
                    ProvideDefaultNamespace(ref serviceContractName);
                    string str = NamingHelper.GetMessageAction(new XmlQualifiedName(serviceContractName.LocalName, serviceContractName.NamespaceName), operationName, null, isResponse);
                    CorrelationActionMessageFilter filter2 = new CorrelationActionMessageFilter {
                        Action = str
                    };
                    item.Where = filter2;
                }
                collection.Add(item);
                if (isResponse)
                {
                    CorrelationQuery query2 = item.Clone();
                    CorrelationActionMessageFilter filter3 = new CorrelationActionMessageFilter {
                        Action = string.Empty
                    };
                    query2.Where = filter3;
                    collection.Add(query2);
                }
            }
            return(collection);
        }
        private void CreateWorkflowManagementEndpoint(WorkflowServiceHost workflowServiceHost)
        {
            Binding          namedPipeControlEndpointBinding;
            IChannelListener listener;

            if (workflowServiceHost.InternalBaseAddresses.Contains(Uri.UriSchemeNetPipe))
            {
                namedPipeControlEndpointBinding = NamedPipeControlEndpointBinding;
            }
            else if (workflowServiceHost.InternalBaseAddresses.Contains(Uri.UriSchemeHttp))
            {
                namedPipeControlEndpointBinding = HttpControlEndpointBinding;
            }
            else
            {
                return;
            }
            Uri listenUriBaseAddress        = ServiceHostBase.GetVia(namedPipeControlEndpointBinding.Scheme, new Uri("System.ServiceModel.Activities_IWorkflowInstanceManagement", UriKind.Relative), workflowServiceHost.InternalBaseAddresses);
            XmlQualifiedName   contractName = new XmlQualifiedName("IWorkflowInstanceManagement", "http://schemas.datacontract.org/2008/10/WorkflowServices");
            EndpointAddress    address      = new EndpointAddress(listenUriBaseAddress.AbsoluteUri);
            EndpointDispatcher item         = new EndpointDispatcher(address, "IWorkflowInstanceManagement", "http://schemas.datacontract.org/2008/10/WorkflowServices", true)
            {
                ContractFilter = new ActionMessageFilter(new string[] { NamingHelper.GetMessageAction(contractName, "Abandon", null, false), NamingHelper.GetMessageAction(contractName, "Cancel", null, false), NamingHelper.GetMessageAction(contractName, "Run", null, false), NamingHelper.GetMessageAction(contractName, "Suspend", null, false), NamingHelper.GetMessageAction(contractName, "Terminate", null, false), NamingHelper.GetMessageAction(contractName, "TransactedCancel", null, false), NamingHelper.GetMessageAction(contractName, "TransactedRun", null, false), NamingHelper.GetMessageAction(contractName, "TransactedSuspend", null, false), NamingHelper.GetMessageAction(contractName, "TransactedTerminate", null, false), NamingHelper.GetMessageAction(contractName, "TransactedUnsuspend", null, false), NamingHelper.GetMessageAction(contractName, "Unsuspend", null, false) })
            };
            BindingParameterCollection parameters = new BindingParameterCollection();
            VirtualPathExtension       extension  = workflowServiceHost.Extensions.Find <VirtualPathExtension>();

            if (extension != null)
            {
                parameters.Add(extension);
            }
            ChannelProtectionRequirements requirements = new ChannelProtectionRequirements();

            requirements.Add(ChannelProtectionRequirements.CreateFromContract(WorkflowControlEndpoint.WorkflowControlServiceContract, ProtectionLevel.EncryptAndSign, ProtectionLevel.EncryptAndSign, false));
            parameters.Add(requirements);
            if (namedPipeControlEndpointBinding.CanBuildChannelListener <IDuplexSessionChannel>(new object[] { listenUriBaseAddress, parameters }))
            {
                listener = namedPipeControlEndpointBinding.BuildChannelListener <IDuplexSessionChannel>(listenUriBaseAddress, parameters);
            }
            else if (namedPipeControlEndpointBinding.CanBuildChannelListener <IReplySessionChannel>(new object[] { listenUriBaseAddress, parameters }))
            {
                listener = namedPipeControlEndpointBinding.BuildChannelListener <IReplySessionChannel>(listenUriBaseAddress, parameters);
            }
            else
            {
                listener = namedPipeControlEndpointBinding.BuildChannelListener <IReplyChannel>(listenUriBaseAddress, parameters);
            }
            foreach (OperationDescription description in WorkflowControlEndpoint.WorkflowControlServiceContract.Operations)
            {
                bool flag;
                bool flag2;
                DataContractSerializerOperationBehavior behavior = new DataContractSerializerOperationBehavior(description);
                DispatchOperation operation = new DispatchOperation(item.DispatchRuntime, description.Name, NamingHelper.GetMessageAction(description, false), NamingHelper.GetMessageAction(description, true))
                {
                    Formatter = (IDispatchMessageFormatter)behavior.GetFormatter(description, out flag, out flag2, false),
                    Invoker   = new ControlOperationInvoker(description, new WorkflowControlEndpoint(namedPipeControlEndpointBinding, address), null, workflowServiceHost)
                };
                item.DispatchRuntime.Operations.Add(operation);
                OperationBehaviorAttribute attribute = description.Behaviors.Find <OperationBehaviorAttribute>();
                ((IOperationBehavior)attribute).ApplyDispatchBehavior(description, operation);
                if (attribute.TransactionScopeRequired)
                {
                    ((ITransactionChannelManager)listener).Dictionary.Add(new DirectionalAction(MessageDirection.Input, NamingHelper.GetMessageAction(description, false)), TransactionFlowOption.Allowed);
                }
            }
            DispatchRuntime dispatchRuntime = item.DispatchRuntime;

            dispatchRuntime.ConcurrencyMode             = ConcurrencyMode.Multiple;
            dispatchRuntime.InstanceContextProvider     = new DurableInstanceContextProvider(workflowServiceHost);
            dispatchRuntime.InstanceProvider            = new DurableInstanceProvider(workflowServiceHost);
            dispatchRuntime.ServiceAuthorizationManager = new WindowsAuthorizationManager(this.WindowsGroup);
            ServiceDebugBehavior     behavior2  = workflowServiceHost.Description.Behaviors.Find <ServiceDebugBehavior>();
            ServiceBehaviorAttribute attribute2 = workflowServiceHost.Description.Behaviors.Find <ServiceBehaviorAttribute>();
            bool flag3 = false;

            if (behavior2 != null)
            {
                flag3 |= behavior2.IncludeExceptionDetailInFaults;
            }
            if (attribute2 != null)
            {
                flag3 |= attribute2.IncludeExceptionDetailInFaults;
            }
            ChannelDispatcher dispatcher4 = new ChannelDispatcher(listener, namedPipeControlEndpointBinding.Name, namedPipeControlEndpointBinding)
            {
                MessageVersion = namedPipeControlEndpointBinding.MessageVersion
            };

            dispatcher4.Endpoints.Add(item);
            dispatcher4.ServiceThrottle = workflowServiceHost.ServiceThrottle;
            ChannelDispatcher dispatcher2 = dispatcher4;

            workflowServiceHost.ChannelDispatchers.Add(dispatcher2);
        }
Ejemplo n.º 13
0
        public static void EnsureTransactionFlowOnContract(
            ref ServiceEndpoint serviceEndpoint,
            XName serviceContractName,
            string operationName,
            string action,
            ProtectionLevel?protectionLevel)
        {
            Fx.Assert(serviceEndpoint != null, "ServiceEndpoint cannot be null!");

            // Client side fully inferred contract always has null ContractType
            if (serviceEndpoint.Contract.ContractType == null)
            {
                // If we are using the real contract, we only need to add TrancactionFlowAttribute to the operation
                Fx.Assert(serviceEndpoint.Contract.Operations.Count == 1, "Client side contract should have exactly one operation!");

                serviceEndpoint.Contract.Operations[0].Behaviors.Add(new TransactionFlowAttribute(TransactionFlowOption.Allowed));
            }
            else
            {
                // Replace the original fake contract with a fake contract tailored for transaction

                ContractDescription  contract  = null;
                OperationDescription operation = null;
                MessageDescription   request   = null;
                MessageDescription   reply     = null;

                Type channelType = typeof(IRequestChannel);

                // We need to create a contract description with the real service contract name
                // and operation name and actions and with the TransactionFlow operation behavior
                // because the TransactionChannelFactory has a dictionary of "Directional Action" to
                // transaction flow value that it uses to decide whether or not to include the
                // transaction header in the message.
                Fx.Assert(serviceContractName != null, "Argument serviceContractName cannot be null!");
                Fx.Assert(operationName != null, "Argument operationName cannot be null!");

                ProvideDefaultNamespace(ref serviceContractName);

                contract = new ContractDescription(serviceContractName.LocalName, serviceContractName.NamespaceName)
                {
                    ContractType = channelType,
                    SessionMode  = SessionMode.Allowed
                };
                operation = new OperationDescription(operationName, contract);
                operation.Behaviors.Add(new TransactionFlowAttribute(TransactionFlowOption.Allowed));

                string requestAction = null;
                string replyAction   = null;
                if (String.IsNullOrEmpty(action))
                {
                    // Construct the action.
                    requestAction = NamingHelper.GetMessageAction(operation, false);
                    replyAction   = NamingHelper.GetMessageAction(operation, true);
                }
                else
                {
                    requestAction = action;
                    replyAction   = action + TypeLoader.ResponseSuffix;
                }

                request = new MessageDescription(requestAction, MessageDirection.Input);
                reply   = new MessageDescription(replyAction, MessageDirection.Output);

                operation.Messages.Add(request);
                operation.Messages.Add(reply);

                if (protectionLevel.HasValue)
                {
                    operation.ProtectionLevel = protectionLevel.Value;
                }

                contract.Operations.Add(operation);

                // We need to replace the ServiceEndpoint because ServiceEndpoint.Contract does not have a public setter
                Uri listenUri = serviceEndpoint.ListenUri;
                serviceEndpoint = new ServiceEndpoint(contract)
                {
                    Binding = serviceEndpoint.Binding,
                    Address = serviceEndpoint.Address,
                    Name    = serviceEndpoint.Name,
                };
                if (listenUri != null)
                {
                    serviceEndpoint.ListenUri = listenUri;
                }
            }
        }
        void CreateWorkflowManagementEndpoint(WorkflowServiceHost workflowServiceHost)
        {
            Binding controlEndpointBinding;

            if (workflowServiceHost.InternalBaseAddresses.Contains(Uri.UriSchemeNetPipe))
            {
                controlEndpointBinding = NamedPipeControlEndpointBinding;
            }
            else if (workflowServiceHost.InternalBaseAddresses.Contains(Uri.UriSchemeHttp))
            {
                controlEndpointBinding = HttpControlEndpointBinding;
            }
            else
            {
                return;
            }

            Uri controlEndpointAddress    = ServiceHost.GetVia(controlEndpointBinding.Scheme, new Uri(ControlEndpointAddress, UriKind.Relative), workflowServiceHost.InternalBaseAddresses);
            XmlQualifiedName contractName = new XmlQualifiedName(XD2.WorkflowInstanceManagementService.ContractName, XD2.WorkflowServices.Namespace);
            //Create the Endpoint Dispatcher
            EndpointAddress    address            = new EndpointAddress(controlEndpointAddress.AbsoluteUri);
            EndpointDispatcher endpointDispatcher = new EndpointDispatcher(address,
                                                                           XD2.WorkflowInstanceManagementService.ContractName,
                                                                           XD2.WorkflowServices.Namespace, true)
            {
                ContractFilter = new ActionMessageFilter(
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.Abandon, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.Cancel, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.Run, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.Suspend, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.Terminate, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.TransactedCancel, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.TransactedRun, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.TransactedSuspend, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.TransactedTerminate, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.TransactedUnsuspend, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.TransactedUpdate, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.Unsuspend, null, false),
                    NamingHelper.GetMessageAction(contractName, XD2.WorkflowInstanceManagementService.Update, null, false)),
            };

            //Create Listener
            ServiceEndpoint            endpoint   = new ServiceEndpoint(WorkflowControlEndpoint.WorkflowControlServiceContract, controlEndpointBinding, address);
            BindingParameterCollection parameters = workflowServiceHost.GetBindingParameters(endpoint);

            IChannelListener listener;

            if (controlEndpointBinding.CanBuildChannelListener <IDuplexSessionChannel>(controlEndpointAddress, parameters))
            {
                listener = controlEndpointBinding.BuildChannelListener <IDuplexSessionChannel>(controlEndpointAddress, parameters);
            }
            else if (controlEndpointBinding.CanBuildChannelListener <IReplySessionChannel>(controlEndpointAddress, parameters))
            {
                listener = controlEndpointBinding.BuildChannelListener <IReplySessionChannel>(controlEndpointAddress, parameters);
            }
            else
            {
                listener = controlEndpointBinding.BuildChannelListener <IReplyChannel>(controlEndpointAddress, parameters);
            }

            //Add the operations
            bool formatRequest;
            bool formatReply;

            foreach (OperationDescription operation in WorkflowControlEndpoint.WorkflowControlServiceContract.Operations)
            {
                DataContractSerializerOperationBehavior dataContractSerializerOperationBehavior = new DataContractSerializerOperationBehavior(operation);

                DispatchOperation operationDispatcher = new DispatchOperation(endpointDispatcher.DispatchRuntime, operation.Name,
                                                                              NamingHelper.GetMessageAction(operation, false), NamingHelper.GetMessageAction(operation, true))
                {
                    Formatter = (IDispatchMessageFormatter)dataContractSerializerOperationBehavior.GetFormatter(operation, out formatRequest, out formatReply, false),
                    Invoker   = new ControlOperationInvoker(
                        operation,
                        new WorkflowControlEndpoint(controlEndpointBinding, address),
                        null,
                        workflowServiceHost),
                };
                endpointDispatcher.DispatchRuntime.Operations.Add(operationDispatcher);

                OperationBehaviorAttribute operationAttribute = operation.Behaviors.Find <OperationBehaviorAttribute>();
                ((IOperationBehavior)operationAttribute).ApplyDispatchBehavior(operation, operationDispatcher);
            }

            DispatchRuntime dispatchRuntime = endpointDispatcher.DispatchRuntime;

            dispatchRuntime.ConcurrencyMode             = ConcurrencyMode.Multiple;
            dispatchRuntime.InstanceContextProvider     = new DurableInstanceContextProvider(workflowServiceHost);
            dispatchRuntime.InstanceProvider            = new DurableInstanceProvider(workflowServiceHost);
            dispatchRuntime.ServiceAuthorizationManager = new WindowsAuthorizationManager(this.WindowsGroup);

            //Create the Channel Dispatcher
            ServiceDebugBehavior     serviceDebugBehavior     = workflowServiceHost.Description.Behaviors.Find <ServiceDebugBehavior>();
            ServiceBehaviorAttribute serviceBehaviorAttribute = workflowServiceHost.Description.Behaviors.Find <ServiceBehaviorAttribute>();

            bool includeDebugInfo = false;

            if (serviceDebugBehavior != null)
            {
                includeDebugInfo |= serviceDebugBehavior.IncludeExceptionDetailInFaults;
            }
            if (serviceBehaviorAttribute != null)
            {
                includeDebugInfo |= serviceBehaviorAttribute.IncludeExceptionDetailInFaults;
            }

            ChannelDispatcher channelDispatcher = new ChannelDispatcher(listener, controlEndpointBinding.Name, controlEndpointBinding)
            {
                MessageVersion  = controlEndpointBinding.MessageVersion,
                Endpoints       = { endpointDispatcher },
                ServiceThrottle = workflowServiceHost.ServiceThrottle
            };

            workflowServiceHost.ChannelDispatchers.Add(channelDispatcher);
        }
Ejemplo n.º 15
0
        //
        // Note - the code below this line a paraphrase of the SM reflection code in TypeLoader.cs
        // Ideally we would be re-using their code, but our assumptions are too disjoint
        // for that to be realistic at the time of writing (12/2004).
        //

        OperationDescription CreateOperationDescription(ContractDescription contract, MethodInfo methodInfo, ComContractElement config, bool allowReferences)
        {
            XmlName operationName   = new XmlName(ServiceReflector.GetLogicalName(methodInfo));
            XmlName returnValueName = TypeLoader.GetReturnValueName(operationName);

            if (ServiceReflector.IsBegin(methodInfo) || ServiceReflector.IsTask(methodInfo))
            {
                Fx.Assert("No async operations allowed");

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NoAsyncOperationsAllowed());
            }
            if (contract.Operations.FindAll(operationName.EncodedName).Count != 0)
            {
                Fx.Assert("Duplicate operation name");

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.DuplicateOperation());
            }

            OperationDescription operationDescription = new OperationDescription(operationName.EncodedName, contract);

            operationDescription.SyncMethod    = methodInfo;
            operationDescription.IsInitiating  = true;
            operationDescription.IsTerminating = false;

            operationDescription.KnownTypes.Add(typeof(Array));
            operationDescription.KnownTypes.Add(typeof(DBNull));
            operationDescription.KnownTypes.Add(typeof(CurrencyWrapper));
            operationDescription.KnownTypes.Add(typeof(ErrorWrapper));

            if (allowReferences)
            {
                operationDescription.KnownTypes.Add(typeof(PersistStreamTypeWrapper));
            }

            foreach (ComUdtElement udt in config.UserDefinedTypes)
            {
                Type knownType;

                Guid typeLibID = Fx.CreateGuid(udt.TypeLibID);

                TypeCacheManager.Provider.FindOrCreateType(typeLibID, udt.TypeLibVersion, Fx.CreateGuid(udt.TypeDefID), out knownType, false);

                this.info.AddUdt(knownType, typeLibID);
                operationDescription.KnownTypes.Add(knownType);
            }


            string           ns            = contract.Namespace;
            XmlQualifiedName contractQName = new XmlQualifiedName(contract.Name, ns);

            string requestAction = NamingHelper.GetMessageAction(contractQName,
                                                                 operationName.DecodedName,
                                                                 null,
                                                                 false);

            string responseAction = NamingHelper.GetMessageAction(contractQName,
                                                                  operationName.DecodedName,
                                                                  null,
                                                                  true);

            MessageDescription inMessage = CreateIncomingMessageDescription(contract,
                                                                            methodInfo,
                                                                            ns,
                                                                            requestAction,
                                                                            allowReferences);

            MessageDescription outMessage = CreateOutgoingMessageDescription(contract,
                                                                             methodInfo,
                                                                             returnValueName,
                                                                             ns,
                                                                             responseAction,
                                                                             allowReferences);

            operationDescription.Messages.Add(inMessage);
            operationDescription.Messages.Add(outMessage);

            return(operationDescription);
        }