public override void OnIncomingMessage(Message message)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            ContextMessageProperty newContext = null;

            if (base.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
            {
                newContext = this.OnReceiveHttpCookies(message);
            }
            else
            {
                newContext = this.OnReceiveSoapContextHeader(message);
            }
            if (newContext != null)
            {
                if (this.contextManagementEnabled)
                {
                    this.EnsureInvariants(true, newContext);
                }
                else
                {
                    newContext.AddOrReplaceInMessage(message);
                }
            }
            if (message.Headers.FindHeader("CallbackContext", "http://schemas.microsoft.com/ws/2008/02/context") != -1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new ProtocolException(System.ServiceModel.SR.GetString("CallbackContextNotExpectedOnIncomingMessageAtClient", new object[] { message.Headers.Action, "CallbackContext", "http://schemas.microsoft.com/ws/2008/02/context" })));
            }
        }
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            try
            {
                if (reply != null)
                {
                    ContextMessageProperty context = null;

                    if (sessionMode == SessionMode.NotAllowed || reply.Properties.ContainsKey(suppressContextOnReply))
                    {
                        if (ContextMessageProperty.TryGet(reply, out context))
                        {
                            context.Context.Clear();
                        }
                    }
                    else
                    {
                        string newInstanceId = correlationState as string;

                        if (newInstanceId != null)
                        {

                            if (!ContextMessageProperty.TryGet(reply, out context))
                            {
                                context = new ContextMessageProperty();
                                context.Context[WellKnownContextProperties.InstanceId] = newInstanceId;
                                context.AddOrReplaceInMessage(reply);
                            }
                            else
                            {
                                context.Context[WellKnownContextProperties.InstanceId] = newInstanceId;
                            }
                        }
                    }
                }
            }
            finally
            {
                DurableInstance durableInstance = OperationContext.Current.InstanceContext.Extensions.Find<DurableInstance>();

                if (durableInstance == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new InvalidOperationException(
                        SR2.GetString(
                        SR2.RequiredInstanceContextExtensionNotFound,
                        typeof(DurableInstance).Name)));
                }
                //Decrement InstanceActivity Count
                durableInstance.DecrementActivityCount();
            }
        }
Esempio n. 3
0
        private void OnReceiveSoapContextHeader(Message message)
        {
            ContextMessageProperty contextFromHeaderIfExists = ContextMessageHeader.GetContextFromHeaderIfExists(message);

            if (contextFromHeaderIfExists != null)
            {
                contextFromHeaderIfExists.AddOrReplaceInMessage(message);
                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    TraceUtility.TraceEvent(TraceEventType.Verbose, 0xf0006, System.ServiceModel.SR.GetString("TraceCodeContextProtocolContextRetrievedFromMessage"), this);
                }
            }
        }
        void OnReceiveSoapContextHeader(Message message)
        {
            ContextMessageProperty messageContext = ContextMessageHeader.GetContextFromHeaderIfExists(message);

            if (messageContext != null)
            {
                messageContext.AddOrReplaceInMessage(message);

                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    TraceUtility.TraceEvent(System.Diagnostics.TraceEventType.Verbose,
                                            TraceCode.ContextProtocolContextRetrievedFromMessage,
                                            SR.GetString(SR.TraceCodeContextProtocolContextRetrievedFromMessage),
                                            this);
                }
            }
        }
Esempio n. 5
0
        public override void OnIncomingMessage(Message message)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }

            ContextMessageProperty incomingContext = null;

            if (this.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
            {
                incomingContext = this.OnReceiveHttpCookies(message);
            }
            else
            {
                incomingContext = this.OnReceiveSoapContextHeader(message);
            }

            if (incomingContext != null)
            {
                if (this.contextManagementEnabled)
                {
                    EnsureInvariants(true, incomingContext);
                }
                else
                {
                    incomingContext.AddOrReplaceInMessage(message);
                }
            }

            // verify that the callback context was not sent on an incoming message
            if (message.Headers.FindHeader(CallbackContextMessageHeader.CallbackContextHeaderName, CallbackContextMessageHeader.CallbackContextHeaderNamespace) != -1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new ProtocolException(SR.GetString(SR.CallbackContextNotExpectedOnIncomingMessageAtClient, message.Headers.Action, CallbackContextMessageHeader.CallbackContextHeaderName, CallbackContextMessageHeader.CallbackContextHeaderNamespace)));
            }
        }