コード例 #1
0
        void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            for (int i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++)
            {
                ChannelDispatcher channelDispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher;
                if (channelDispatcher != null)
                {
                    channelDispatcher.IncludeExceptionDetailInFaults = this.includeExceptionDetailInFaults;

                    if (channelDispatcher.HasApplicationEndpoints())
                    {
                        channelDispatcher.TransactionTimeout = transactionTimeout;
                        if (isolationLevelSet)
                        {
                            SetIsolationLevel(channelDispatcher);
                        }

                        foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                        {
                            if (endpointDispatcher.IsSystemEndpoint)
                            {
                                continue;
                            }
                            DispatchRuntime behavior = endpointDispatcher.DispatchRuntime;
                            behavior.ConcurrencyMode                             = this.concurrencyMode;
                            behavior.EnsureOrderedDispatch                       = this.ensureOrderedDispatch;
                            behavior.ValidateMustUnderstand                      = validateMustUnderstand;
                            behavior.AutomaticInputSessionShutdown               = this.automaticSessionShutdown;
                            behavior.TransactionAutoCompleteOnSessionClose       = this.transactionAutoCompleteOnSessionClose;
                            behavior.ReleaseServiceInstanceOnTransactionComplete = this.releaseServiceInstanceOnTransactionComplete;
                            if (!this.useSynchronizationContext)
                            {
                                behavior.SynchronizationContext = null;
                            }

                            if (!endpointDispatcher.AddressFilterSetExplicit)
                            {
                                EndpointAddress address = endpointDispatcher.OriginalAddress;
                                if (address == null || this.AddressFilterMode == AddressFilterMode.Any)
                                {
                                    endpointDispatcher.AddressFilter = new MatchAllMessageFilter();
                                }
                                else if (this.AddressFilterMode == AddressFilterMode.Prefix)
                                {
                                    endpointDispatcher.AddressFilter = new PrefixEndpointAddressMessageFilter(address);
                                }
                                else if (this.AddressFilterMode == AddressFilterMode.Exact)
                                {
                                    endpointDispatcher.AddressFilter = new EndpointAddressMessageFilter(address);
                                }
                            }
                        }
                    }
#pragma warning suppress 56506
                }
            }
            DataContractSerializerServiceBehavior.ApplySerializationSettings(description, ignoreExtensionDataObject, maxItemsInObjectGraph);
            ApplyInstancing(description, serviceHostBase);
        }
コード例 #2
0
 void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
 {
     for (int index = 0; index < serviceHostBase.ChannelDispatchers.Count; ++index)
     {
         ChannelDispatcher channelDispatcher = serviceHostBase.ChannelDispatchers[index] as ChannelDispatcher;
         if (channelDispatcher != null)
         {
             channelDispatcher.IncludeExceptionDetailInFaults = this.includeExceptionDetailInFaults;
             if (channelDispatcher.HasApplicationEndpoints())
             {
                 channelDispatcher.TransactionTimeout = this.transactionTimeout;
                 if (this.isolationLevelSet)
                 {
                     this.SetIsolationLevel(channelDispatcher);
                 }
                 foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                 {
                     if (!endpointDispatcher.IsSystemEndpoint)
                     {
                         DispatchRuntime dispatchRuntime = endpointDispatcher.DispatchRuntime;
                         dispatchRuntime.ConcurrencyMode                             = this.concurrencyMode;
                         dispatchRuntime.ValidateMustUnderstand                      = this.validateMustUnderstand;
                         dispatchRuntime.AutomaticInputSessionShutdown               = this.automaticSessionShutdown;
                         dispatchRuntime.TransactionAutoCompleteOnSessionClose       = this.transactionAutoCompleteOnSessionClose;
                         dispatchRuntime.ReleaseServiceInstanceOnTransactionComplete = this.releaseServiceInstanceOnTransactionComplete;
                         if (!this.useSynchronizationContext)
                         {
                             dispatchRuntime.SynchronizationContext = (SynchronizationContext)null;
                         }
                         if (!endpointDispatcher.AddressFilterSetExplicit)
                         {
                             EndpointAddress originalAddress = endpointDispatcher.OriginalAddress;
                             if (originalAddress == (EndpointAddress)null || this.AddressFilterMode == AddressFilterMode.Any)
                             {
                                 endpointDispatcher.AddressFilter = (MessageFilter) new MatchAllMessageFilter();
                             }
                             else if (this.AddressFilterMode == AddressFilterMode.Prefix)
                             {
                                 endpointDispatcher.AddressFilter = (MessageFilter) new PrefixEndpointAddressMessageFilter(originalAddress);
                             }
                             else if (this.AddressFilterMode == AddressFilterMode.Exact)
                             {
                                 endpointDispatcher.AddressFilter = (MessageFilter) new EndpointAddressMessageFilter(originalAddress);
                             }
                         }
                     }
                 }
             }
         }
     }
     DataContractSerializerServiceBehavior.ApplySerializationSettings(description, this.ignoreExtensionDataObject, this.maxItemsInObjectGraph);
     this.ApplyInstancing(description, serviceHostBase);
 }
コード例 #3
0
 void IServiceBehavior.ApplyDispatchBehavior(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase serviceHostBase)
 {
     if (this.transactionTimeout != TimeSpan.Zero)
     {
         for (int i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++)
         {
             ChannelDispatcher dispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher;
             if (((dispatcher != null) && dispatcher.HasApplicationEndpoints()) && ((dispatcher.TransactionTimeout == TimeSpan.Zero) || (dispatcher.TransactionTimeout > this.transactionTimeout)))
             {
                 dispatcher.TransactionTimeout = this.transactionTimeout;
             }
         }
     }
 }
コード例 #4
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            if (serviceDescription == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceDescription");
            }

            if (serviceHostBase == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase");
            }

            if (serviceDescription.Endpoints == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("serviceDescription", SR2.GetString(SR2.NoEndpoints));
            }

            PersistenceProviderBehavior providerBehavior = null;

            if (serviceDescription.Behaviors != null)
            {
                providerBehavior = serviceDescription.Behaviors.Find <PersistenceProviderBehavior>();
            }

            if (providerBehavior == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(
                              SR2.GetString(
                                  SR2.NonNullPersistenceProviderRequired,
                                  typeof(PersistenceProvider).Name,
                                  typeof(DurableServiceAttribute).Name)));
            }

            if (providerBehavior.PersistenceProviderFactory == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(
                              SR2.GetString(
                                  SR2.NonNullPersistenceProviderRequired,
                                  typeof(PersistenceProvider).Name,
                                  typeof(DurableServiceAttribute).Name)));
            }

            providerBehavior.PersistenceProviderFactory.Open();
            serviceHostBase.Closed += new EventHandler(
                delegate(object sender, EventArgs args)
            {
                Fx.Assert(sender is ServiceHostBase, "The sender should be serviceHostBase.");
                // We have no way of knowing whether the service host closed or aborted
                // so we err on the side of abort for right now.
                providerBehavior.PersistenceProviderFactory.Abort();
            }
                );

            DurableInstanceContextProvider instanceContextProvider = new ServiceDurableInstanceContextProvider(
                serviceHostBase,
                false,
                serviceDescription.ServiceType,
                providerBehavior.PersistenceProviderFactory,
                this.saveStateInOperationTransaction,
                this.unknownExceptionAction,
                new DurableRuntimeValidator(this.saveStateInOperationTransaction, this.unknownExceptionAction),
                providerBehavior.PersistenceOperationTimeout);

            DurableInstanceContextProvider singleCallInstanceContextProvider = null;

            IInstanceProvider instanceProvider = new DurableInstanceProvider(instanceContextProvider);

            bool includeExceptionDetails = false;

            if (serviceDescription.Behaviors != null)
            {
                ServiceBehaviorAttribute serviceBehavior = serviceDescription.Behaviors.Find <ServiceBehaviorAttribute>();

                if (serviceBehavior != null)
                {
                    includeExceptionDetails |= serviceBehavior.IncludeExceptionDetailInFaults;
                }

                ServiceDebugBehavior serviceDebugBehavior = serviceDescription.Behaviors.Find <ServiceDebugBehavior>();

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

            IErrorHandler errorHandler = new ServiceErrorHandler(includeExceptionDetails);

            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;

                if (channelDispatcher != null && channelDispatcher.HasApplicationEndpoints())
                {
                    if (this.unknownExceptionAction == UnknownExceptionAction.AbortInstance)
                    {
                        channelDispatcher.ErrorHandlers.Add(errorHandler);
                    }

                    foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                    {
                        if (endpointDispatcher.IsSystemEndpoint)
                        {
                            continue;
                        }
                        ServiceEndpoint serviceEndPoint = serviceDescription.Endpoints.Find(new XmlQualifiedName(endpointDispatcher.ContractName, endpointDispatcher.ContractNamespace));

                        if (serviceEndPoint != null)
                        {
                            if (serviceEndPoint.Contract.SessionMode != SessionMode.NotAllowed)
                            {
                                endpointDispatcher.DispatchRuntime.InstanceContextProvider = instanceContextProvider;
                            }
                            else
                            {
                                if (singleCallInstanceContextProvider == null)
                                {
                                    singleCallInstanceContextProvider = new ServiceDurableInstanceContextProvider(
                                        serviceHostBase,
                                        true,
                                        serviceDescription.ServiceType,
                                        providerBehavior.PersistenceProviderFactory,
                                        this.saveStateInOperationTransaction,
                                        this.unknownExceptionAction,
                                        new DurableRuntimeValidator(this.saveStateInOperationTransaction, this.unknownExceptionAction),
                                        providerBehavior.PersistenceOperationTimeout);
                                }
                                endpointDispatcher.DispatchRuntime.InstanceContextProvider = singleCallInstanceContextProvider;
                            }
                            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new DurableMessageDispatchInspector(serviceEndPoint.Contract.SessionMode));
                            endpointDispatcher.DispatchRuntime.InstanceProvider = instanceProvider;
                            WorkflowServiceBehavior.SetContractFilterToIncludeAllOperations(endpointDispatcher, serviceEndPoint.Contract);
                        }
                    }
                }
            }

            foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
            {
                if (!endpoint.InternalIsSystemEndpoint(serviceDescription))
                {
                    foreach (OperationDescription opDescription in endpoint.Contract.Operations)
                    {
                        if (!opDescription.Behaviors.Contains(typeof(DurableOperationAttribute)))
                        {
                            opDescription.Behaviors.Add(DurableOperationAttribute.DefaultInstance);
                        }
                    }
                }
            }
        }
コード例 #5
0
        public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            if (description == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
            }

            if (serviceHostBase == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase");
            }
            if (description.Behaviors == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("description", SR2.GetString(SR2.NoBehaviors));
            }
            if (description.Endpoints == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("description", SR2.GetString(SR2.NoEndpoints));
            }

            bool syncContextRegistered = false;
            WorkflowRuntimeBehavior workflowRuntimeBehavior = description.Behaviors.Find <WorkflowRuntimeBehavior>();

            if (workflowRuntimeBehavior == null)
            {
                workflowRuntimeBehavior = new WorkflowRuntimeBehavior();
                description.Behaviors.Add(workflowRuntimeBehavior);
            }

            WorkflowPersistenceService persistenceService = workflowRuntimeBehavior.WorkflowRuntime.GetService <WorkflowPersistenceService>();

            if (persistenceService != null)
            {
                bool wasRuntimeStarted = workflowRuntimeBehavior.WorkflowRuntime.IsStarted;
                if (wasRuntimeStarted)
                {
                    workflowRuntimeBehavior.WorkflowRuntime.StopRuntime();
                }
                workflowRuntimeBehavior.WorkflowRuntime.RemoveService(persistenceService);
                workflowRuntimeBehavior.WorkflowRuntime.AddService(new SkipUnloadOnFirstIdleWorkflowPersistenceService(persistenceService));
                if (wasRuntimeStarted)
                {
                    workflowRuntimeBehavior.WorkflowRuntime.StartRuntime();
                }
            }

            this.workflowDefinitionContext.Register(workflowRuntimeBehavior.WorkflowRuntime, workflowRuntimeBehavior.ValidateOnCreate);

            WorkflowInstanceContextProvider instanceContextProvider = new WorkflowInstanceContextProvider(
                serviceHostBase,
                false,
                this.workflowDefinitionContext
                );

            WorkflowInstanceContextProvider singleCallInstanceContextProvider = null;

            IInstanceProvider    instanceProvider     = new WorkflowInstanceProvider(instanceContextProvider);
            ServiceDebugBehavior serviceDebugBehavior = description.Behaviors.Find <ServiceDebugBehavior>();

            bool includeExceptionDetailsInFaults = this.IncludeExceptionDetailInFaults;

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

            IErrorHandler workflowOperationErrorHandler = new WorkflowOperationErrorHandler(includeExceptionDetailsInFaults);

            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;

                if (channelDispatcher != null && channelDispatcher.HasApplicationEndpoints())
                {
                    channelDispatcher.IncludeExceptionDetailInFaults = includeExceptionDetailsInFaults;
                    channelDispatcher.ErrorHandlers.Add(workflowOperationErrorHandler);
                    foreach (EndpointDispatcher endPointDispatcher in channelDispatcher.Endpoints)
                    {
                        if (endPointDispatcher.IsSystemEndpoint)
                        {
                            continue;
                        }

                        ServiceEndpoint serviceEndPoint = description.Endpoints.Find(new XmlQualifiedName(endPointDispatcher.ContractName, endPointDispatcher.ContractNamespace));

                        if (serviceEndPoint != null)
                        {
                            DispatchRuntime dispatchRuntime = endPointDispatcher.DispatchRuntime;

                            dispatchRuntime.AutomaticInputSessionShutdown = true;
                            dispatchRuntime.ConcurrencyMode        = ConcurrencyMode.Single;
                            dispatchRuntime.ValidateMustUnderstand = this.ValidateMustUnderstand;

                            if (!this.UseSynchronizationContext)
                            {
                                dispatchRuntime.SynchronizationContext = null;
                            }
                            else if (!syncContextRegistered)
                            {
                                SynchronizationContextWorkflowSchedulerService syncSchedulerService = workflowRuntimeBehavior.WorkflowRuntime.GetService <SynchronizationContextWorkflowSchedulerService>();
                                Fx.Assert(syncSchedulerService != null, "Wrong Synchronization Context Set");
                                syncSchedulerService.SetSynchronizationContext(dispatchRuntime.SynchronizationContext);
                                syncContextRegistered = true;
                            }

                            if (!endPointDispatcher.AddressFilterSetExplicit)
                            {
                                EndpointAddress endPointAddress = endPointDispatcher.OriginalAddress;
                                if ((endPointAddress == null) || (this.AddressFilterMode == AddressFilterMode.Any))
                                {
                                    endPointDispatcher.AddressFilter = new MatchAllMessageFilter();
                                }
                                else if (this.AddressFilterMode == AddressFilterMode.Prefix)
                                {
                                    endPointDispatcher.AddressFilter = new PrefixEndpointAddressMessageFilter(endPointAddress);
                                }
                                else if (this.AddressFilterMode == AddressFilterMode.Exact)
                                {
                                    endPointDispatcher.AddressFilter = new EndpointAddressMessageFilter(endPointAddress);
                                }
                            }

                            if (serviceEndPoint.Contract.SessionMode != SessionMode.NotAllowed)
                            {
                                endPointDispatcher.DispatchRuntime.InstanceContextProvider = instanceContextProvider;
                            }
                            else
                            {
                                if (singleCallInstanceContextProvider == null)
                                {
                                    singleCallInstanceContextProvider = new WorkflowInstanceContextProvider(
                                        serviceHostBase,
                                        true,
                                        this.workflowDefinitionContext);
                                }
                                endPointDispatcher.DispatchRuntime.InstanceContextProvider = singleCallInstanceContextProvider;
                            }
                            endPointDispatcher.DispatchRuntime.MessageInspectors.Add(new DurableMessageDispatchInspector(serviceEndPoint.Contract.SessionMode));
                            endPointDispatcher.DispatchRuntime.InstanceProvider = instanceProvider;
                            SetContractFilterToIncludeAllOperations(endPointDispatcher, serviceEndPoint.Contract);
                        }
                    }
                }
            }
            DataContractSerializerServiceBehavior.ApplySerializationSettings(description, this.ignoreExtensionDataObject, this.maxItemsInObjectGraph);
        }