Ejemplo n.º 1
0
        public void GetListenAddressAndContext(out EndpointAddress listenAddress, out IDictionary <string, string> context)
        {
            // we expect the callback address to be already set when this is called
            if (this.CallbackAddress == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callbackaddress");
            }
            EndpointAddressBuilder builder       = new EndpointAddressBuilder(this.CallbackAddress);
            AddressHeader          contextHeader = null;
            int contextHeaderIndex = -1;

            for (int i = 0; i < builder.Headers.Count; ++i)
            {
                if (builder.Headers[i].Name == ContextMessageHeader.ContextHeaderName && builder.Headers[i].Namespace == ContextMessageHeader.ContextHeaderNamespace)
                {
                    if (contextHeader != null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(SR.GetString(SR.MultipleContextHeadersFoundInCallbackAddress)));
                    }
                    contextHeader      = builder.Headers[i];
                    contextHeaderIndex = i;
                }
            }
            if (contextHeader != null)
            {
                builder.Headers.RemoveAt(contextHeaderIndex);
            }
            context       = (contextHeader != null) ? ContextMessageHeader.ParseContextHeader(contextHeader.GetAddressHeaderReader()).Context : null;
            listenAddress = builder.ToEndpointAddress();
        }
Ejemplo n.º 2
0
        public void GetListenAddressAndContext(out EndpointAddress listenAddress, out IDictionary <string, string> context)
        {
            if (this.CallbackAddress == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callbackaddress");
            }
            EndpointAddressBuilder builder = new EndpointAddressBuilder(this.CallbackAddress);
            AddressHeader          header  = null;
            int index = -1;

            for (int i = 0; i < builder.Headers.Count; i++)
            {
                if ((builder.Headers[i].Name == "Context") && (builder.Headers[i].Namespace == "http://schemas.microsoft.com/ws/2006/05/context"))
                {
                    if (header != null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("MultipleContextHeadersFoundInCallbackAddress")));
                    }
                    header = builder.Headers[i];
                    index  = i;
                }
            }
            if (header != null)
            {
                builder.Headers.RemoveAt(index);
            }
            context       = (header != null) ? ContextMessageHeader.ParseContextHeader(header.GetAddressHeaderReader()).Context : null;
            listenAddress = builder.ToEndpointAddress();
        }
Ejemplo n.º 3
0
            public static bool TryCreateFromHttpCookieHeader(string httpCookieHeader, out ContextMessageProperty context)
            {
                if (httpCookieHeader == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("httpCookieHeader");
                }

                context = null;

                foreach (string token in httpCookieHeader.Split(';'))
                {
                    string trimmedToken = token.Trim();
                    if (trimmedToken.StartsWith(HttpCookieToolbox.ContextHttpCookieName, StringComparison.Ordinal))
                    {
                        int equalsSignIndex = trimmedToken.IndexOf('=');
                        if (equalsSignIndex < 0)
                        {
                            context = new ContextMessageProperty();
                            break;
                        }
                        if (equalsSignIndex < (trimmedToken.Length - 1))
                        {
                            string value = trimmedToken.Substring(equalsSignIndex + 1).Trim();

                            if (value.Length > 1 && (value[0] == '"') && (value[value.Length - 1] == '"'))
                            {
                                value = value.Substring(1, value.Length - 2);
                            }
                            try
                            {
                                context = ContextMessageHeader.ParseContextHeader(
                                    XmlReader.Create(new MemoryStream(Convert.FromBase64String(value))));
                                break;
                            }
                            catch (SerializationException e)
                            {
                                DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                            }
                            catch (ProtocolException pe)
                            {
                                DiagnosticUtility.TraceHandledException(pe, TraceEventType.Warning);
                            }
                        }
                    }
                }

                return(context != null);
            }
 public static bool TryCreateFromHttpCookieHeader(string httpCookieHeader, out ContextMessageProperty context)
 {
     if (httpCookieHeader == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("httpCookieHeader");
     }
     context = null;
     foreach (string str in httpCookieHeader.Split(new char[] { ';' }))
     {
         string str2 = str.Trim();
         if (str2.StartsWith("WscContext", StringComparison.Ordinal))
         {
             int index = str2.IndexOf('=');
             if (index < 0)
             {
                 context = new ContextMessageProperty();
                 break;
             }
             if (index < (str2.Length - 1))
             {
                 string s = str2.Substring(index + 1).Trim();
                 if (((s.Length > 1) && (s[0] == '"')) && (s[s.Length - 1] == '"'))
                 {
                     s = s.Substring(1, s.Length - 2);
                 }
                 try
                 {
                     context = ContextMessageHeader.ParseContextHeader(XmlReader.Create(new MemoryStream(Convert.FromBase64String(s))));
                     break;
                 }
                 catch (SerializationException exception)
                 {
                     System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
                 }
                 catch (ProtocolException exception2)
                 {
                     System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Warning);
                 }
             }
         }
     }
     return(context != null);
 }