Example #1
0
        public override void OnOutgoingMessage(Message message, System.ServiceModel.Channels.RequestContext requestContext)
        {
            ContextMessageProperty         property;
            CallbackContextMessageProperty property2;

            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            if (ContextMessageProperty.TryGet(message, out property))
            {
                if (base.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
                {
                    Uri requestUri = null;
                    if (requestContext.RequestMessage.Properties != null)
                    {
                        requestUri = requestContext.RequestMessage.Properties.Via;
                    }
                    if (requestUri == null)
                    {
                        requestUri = requestContext.RequestMessage.Headers.To;
                    }
                    this.OnSendHttpCookies(message, property, requestUri);
                }
                else
                {
                    base.OnSendSoapContextHeader(message, property);
                }
            }
            if (CallbackContextMessageProperty.TryGet(message, out property2))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(System.ServiceModel.SR.GetString("CallbackContextNotExpectedOnOutgoingMessageAtServer", new object[] { message.Headers.Action })));
            }
        }
Example #2
0
        public static string GetContextCorrelationData(OperationContext operationContext)
        {
            ContextMessageProperty contextMessageProperty = null;
            string str = null;

            if (ContextMessageProperty.TryGet(operationContext.OutgoingMessageProperties, out contextMessageProperty))
            {
                contextMessageProperty.Context.TryGetValue("instanceId", out str);
            }
            return(str ?? string.Empty);
        }
Example #3
0
        public static string GetContextCorrelationData(Message message)
        {
            ContextMessageProperty contextMessageProperty = null;
            string str = null;

            if (ContextMessageProperty.TryGet(message, out contextMessageProperty))
            {
                contextMessageProperty.Context.TryGetValue("instanceId", out str);
            }
            return(str ?? string.Empty);
        }
        public static string GetContextCorrelationData(OperationContext operationContext)
        {
            ContextMessageProperty contextProperties = null;
            string instanceId = null;

            if (ContextMessageProperty.TryGet(operationContext.OutgoingMessageProperties, out contextProperties))
            {
                contextProperties.Context.TryGetValue(ContextMessageProperty.InstanceIdKey, out instanceId);
            }

            return(instanceId ?? string.Empty);
        }
        public override void OnOutgoingMessage(Message message, System.ServiceModel.Channels.RequestContext requestContext)
        {
            CallbackContextMessageProperty property2;

            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            ContextMessageProperty contextMessageProperty = null;

            if (ContextMessageProperty.TryGet(message, out contextMessageProperty) && this.contextManagementEnabled)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("InvalidMessageContext")));
            }
            if (base.ContextExchangeMechanism == ContextExchangeMechanism.ContextSoapHeader)
            {
                if (this.contextManagementEnabled)
                {
                    contextMessageProperty = this.GetCurrentContext();
                }
                if (contextMessageProperty != null)
                {
                    base.OnSendSoapContextHeader(message, contextMessageProperty);
                }
            }
            else if (base.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
            {
                if (this.contextManagementEnabled)
                {
                    this.OnSendHttpCookies(message, null);
                }
                else
                {
                    this.OnSendHttpCookies(message, contextMessageProperty);
                }
            }
            if (CallbackContextMessageProperty.TryGet(message, out property2))
            {
                EndpointAddress callbackAddress = property2.CallbackAddress;
                if ((callbackAddress == null) && (this.callbackAddress != null))
                {
                    callbackAddress = property2.CreateCallbackAddress(this.callbackAddress);
                }
                if (callbackAddress != null)
                {
                    if (base.ContextExchangeMechanism != ContextExchangeMechanism.ContextSoapHeader)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CallbackContextOnlySupportedInSoap")));
                    }
                    message.Headers.Add(new CallbackContextMessageHeader(callbackAddress, message.Version.Addressing));
                }
            }
        }
        public override void OnOutgoingMessage(Message message, RequestContext requestContext)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }

            ContextMessageProperty messageContext;

            if (ContextMessageProperty.TryGet(message, out messageContext))
            {
                if (this.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
                {
                    Fx.Assert(requestContext != null, "DuplexChannel shape cannot have ContextExchangeMechanism = HttpCookie");
                    Uri requestUri = null;

                    if (requestContext.RequestMessage.Properties != null)
                    {
                        requestUri = requestContext.RequestMessage.Properties.Via;
                    }
                    if (requestUri == null)
                    {
                        requestUri = requestContext.RequestMessage.Headers.To;
                    }
                    this.OnSendHttpCookies(message, messageContext, requestUri);
                }
                else
                {
                    this.OnSendSoapContextHeader(message, messageContext);
                }
            }
            // verify that the callback context was not attached to an outgoing message
            CallbackContextMessageProperty dummy;

            if (CallbackContextMessageProperty.TryGet(message, out dummy))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR.GetString(SR.CallbackContextNotExpectedOnOutgoingMessageAtServer, message.Headers.Action)));
            }
        }
Example #7
0
        public override void OnOutgoingMessage(Message message, RequestContext requestContext)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }

            ContextMessageProperty outgoingContext = null;

            if (ContextMessageProperty.TryGet(message, out outgoingContext))
            {
                if (this.contextManagementEnabled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new InvalidOperationException(
                                  SR.GetString(SR.InvalidMessageContext)));
                }
            }

            if (this.ContextExchangeMechanism == ContextExchangeMechanism.ContextSoapHeader)
            {
                if (this.contextManagementEnabled)
                {
                    outgoingContext = GetCurrentContext();
                }

                if (outgoingContext != null)
                {
                    this.OnSendSoapContextHeader(message, outgoingContext);
                }
            }
            else if (this.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
            {
                if (this.contextManagementEnabled)
                {
                    this.OnSendHttpCookies(message, null);
                }
                else
                {
                    this.OnSendHttpCookies(message, outgoingContext);
                }
            }

            // serialize the callback context if the property was supplied
            CallbackContextMessageProperty callbackContext;

            if (CallbackContextMessageProperty.TryGet(message, out callbackContext))
            {
                // see if the callbackaddress is already set on the CCMP, if it is set use that
                // else if callbackaddress is set on the binding, use that
                EndpointAddress callbackAddress = callbackContext.CallbackAddress;
                if (callbackAddress == null && this.callbackAddress != null)
                {
                    callbackAddress = callbackContext.CreateCallbackAddress(this.callbackAddress);
                }
                // add the CallbackContextMessageHeader only if we have a valid CallbackAddress
                if (callbackAddress != null)
                {
                    if (this.ContextExchangeMechanism != ContextExchangeMechanism.ContextSoapHeader)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CallbackContextOnlySupportedInSoap)));
                    }
                    message.Headers.Add(new CallbackContextMessageHeader(callbackAddress, message.Version.Addressing));
                }
            }
        }