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

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

            // deserialize the callback context header, if present
            int headerIndex = message.Headers.FindHeader(CallbackContextMessageHeader.CallbackContextHeaderName, CallbackContextMessageHeader.CallbackContextHeaderNamespace);

            if (headerIndex > 0)
            {
                CallbackContextMessageProperty property = CallbackContextMessageHeader.ParseCallbackContextHeader(message.Headers.GetReaderAtHeader(headerIndex), message.Version.Addressing);
                message.Properties.Add(CallbackContextMessageProperty.Name, property);
            }

            ContextExchangeCorrelationHelper.AddIncomingContextCorrelationData(message);
        }
        internal static CallbackContextMessageProperty ParseCallbackContextHeader(XmlReader reader, AddressingVersion version)
        {
            CallbackContextMessageProperty property;

            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }
            if (version != AddressingVersion.WSAddressing10)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("CallbackContextOnlySupportedInWSAddressing10", new object[] { version })));
            }
            try
            {
                reader.ReadStartElement("CallbackContext", "http://schemas.microsoft.com/ws/2008/02/context");
                EndpointAddress callbackAddress = EndpointAddress.ReadFrom(version, reader, "CallbackEndpointReference", "http://schemas.microsoft.com/ws/2008/02/context");
                reader.ReadEndElement();
                property = new CallbackContextMessageProperty(callbackAddress);
            }
            catch (XmlException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("XmlFormatViolationInCallbackContextHeader"), exception));
            }
            return(property);
        }
Example #3
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 #4
0
 public static bool TryGet(Message message, out CallbackContextMessageProperty contextMessageProperty)
 {
     if (message == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
     }
     return(TryGet(message.Properties, out contextMessageProperty));
 }
        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));
                }
            }
        }
Example #6
0
        public static string GetCallbackContextCorrelationData(Message message)
        {
            CallbackContextMessageProperty property;
            string str = null;

            if (CallbackContextMessageProperty.TryGet(message, out property))
            {
                IDictionary <string, string> context = property.Context;
                if (context != null)
                {
                    context.TryGetValue("instanceId", out str);
                }
            }
            return(str ?? string.Empty);
        }
        public static string GetCallbackContextCorrelationData(Message message)
        {
            CallbackContextMessageProperty callbackContext;
            string instanceId = null;

            if (CallbackContextMessageProperty.TryGet(message, out callbackContext))
            {
                IDictionary <string, string> context;
                context = callbackContext.Context;
                if (context != null)
                {
                    context.TryGetValue(ContextMessageProperty.InstanceIdKey, out instanceId);
                }
            }

            return(instanceId ?? string.Empty);
        }
Example #8
0
        public static bool TryGet(MessageProperties properties, out CallbackContextMessageProperty contextMessageProperty)
        {
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }
            object obj2 = null;

            if (properties.TryGetValue("CallbackContextMessageProperty", out obj2))
            {
                contextMessageProperty = obj2 as CallbackContextMessageProperty;
            }
            else
            {
                contextMessageProperty = null;
            }
            return(contextMessageProperty != null);
        }
        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 #10
0
        public override void OnIncomingMessage(Message message)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            if (base.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)
            {
                this.OnReceiveHttpCookies(message);
            }
            else
            {
                this.OnReceiveSoapContextHeader(message);
            }
            int headerIndex = message.Headers.FindHeader("CallbackContext", "http://schemas.microsoft.com/ws/2008/02/context");

            if (headerIndex > 0)
            {
                CallbackContextMessageProperty property = CallbackContextMessageHeader.ParseCallbackContextHeader(message.Headers.GetReaderAtHeader(headerIndex), message.Version.Addressing);
                message.Properties.Add(CallbackContextMessageProperty.Name, property);
            }
            ContextExchangeCorrelationHelper.AddIncomingContextCorrelationData(message);
        }
        public static bool TryGet(MessageProperties properties, out CallbackContextMessageProperty contextMessageProperty)
        {
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }

            object value = null;
            if (properties.TryGetValue(PropertyName, out value))
            {
                contextMessageProperty = value as CallbackContextMessageProperty;
            }
            else
            {
                contextMessageProperty = null;
            }

            return contextMessageProperty != null;
        }
        public static bool TryGet(Message message, out CallbackContextMessageProperty contextMessageProperty)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }

            return TryGet(message.Properties, out contextMessageProperty);
        }
 internal static CallbackContextMessageProperty ParseCallbackContextHeader(XmlReader reader, AddressingVersion version)
 {
     CallbackContextMessageProperty property;
     if (reader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
     }
     if (version != AddressingVersion.WSAddressing10)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("CallbackContextOnlySupportedInWSAddressing10", new object[] { version })));
     }
     try
     {
         reader.ReadStartElement("CallbackContext", "http://schemas.microsoft.com/ws/2008/02/context");
         EndpointAddress callbackAddress = EndpointAddress.ReadFrom(version, reader, "CallbackEndpointReference", "http://schemas.microsoft.com/ws/2008/02/context");
         reader.ReadEndElement();
         property = new CallbackContextMessageProperty(callbackAddress);
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("XmlFormatViolationInCallbackContextHeader"), exception));
     }
     return property;
 }
Example #14
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));
                }
            }
        }