public static string EncodeContextAsHttpSetCookieHeader(ContextMessageProperty context, Uri uri) { if (uri == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } MemoryStream stream = new MemoryStream(); XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.OmitXmlDeclaration = true; XmlWriter writer = XmlWriter.Create(stream, writerSettings); ContextMessageHeader contextHeader = new ContextMessageHeader(context.Context); contextHeader.WriteHeader(writer, MessageVersion.Default); writer.Flush(); string result = string.Format( CultureInfo.InvariantCulture, "{0}=\"{1}\";Path={2}", HttpCookieToolbox.ContextHttpCookieName, Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length), uri.AbsolutePath); return result; }
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(); }
public static string EncodeContextAsHttpSetCookieHeader(ContextMessageProperty context, Uri uri) { if (uri == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } MemoryStream stream = new MemoryStream(); XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.OmitXmlDeclaration = true; XmlWriter writer = XmlWriter.Create(stream, writerSettings); ContextMessageHeader contextHeader = new ContextMessageHeader(context.Context); contextHeader.WriteHeader(writer, MessageVersion.Default); writer.Flush(); string result = string.Format( CultureInfo.InvariantCulture, "{0}=\"{1}\";Path={2}", HttpCookieToolbox.ContextHttpCookieName, Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length), uri.AbsolutePath); return(result); }
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(); }
private ContextMessageProperty OnReceiveSoapContextHeader(Message message) { ContextMessageProperty contextFromHeaderIfExists = ContextMessageHeader.GetContextFromHeaderIfExists(message); if ((contextFromHeaderIfExists != null) && DiagnosticUtility.ShouldTraceVerbose) { TraceUtility.TraceEvent(TraceEventType.Verbose, 0xf0006, System.ServiceModel.SR.GetString("TraceCodeContextProtocolContextRetrievedFromMessage"), this); } return(contextFromHeaderIfExists); }
ContextMessageProperty OnReceiveSoapContextHeader(Message message) { ContextMessageProperty messageProperty = ContextMessageHeader.GetContextFromHeaderIfExists(message); if (messageProperty != null) { if (DiagnosticUtility.ShouldTraceVerbose) { TraceUtility.TraceEvent(System.Diagnostics.TraceEventType.Verbose, TraceCode.ContextProtocolContextRetrievedFromMessage, SR.GetString(SR.TraceCodeContextProtocolContextRetrievedFromMessage), this); } } return(messageProperty); }
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 override T GetProperty <T>(BindingContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (typeof(T) == typeof(ChannelProtectionRequirements) && this.ProtectionLevel != ProtectionLevel.None) { ChannelProtectionRequirements innerRequirements = context.GetInnerProperty <ChannelProtectionRequirements>(); if (innerRequirements == null) { return((T)(object)ContextMessageHeader.GetChannelProtectionRequirements(this.ProtectionLevel)); } else { ChannelProtectionRequirements requirements = new ChannelProtectionRequirements(innerRequirements); requirements.Add(ContextMessageHeader.GetChannelProtectionRequirements(this.ProtectionLevel)); return((T)(object)requirements); } } else if (typeof(T) == typeof(IContextSessionProvider)) { return((T)(object)this); } else if (typeof(T) == typeof(IContextBindingElement)) { return((T)(object)this); } else if (typeof(T) == typeof(ICorrelationDataSource)) { ICorrelationDataSource correlationData = instanceCorrelationData; if (correlationData == null) { ICorrelationDataSource innerCorrelationData = context.GetInnerProperty <ICorrelationDataSource>(); correlationData = CorrelationDataSourceHelper.Combine(innerCorrelationData, ContextExchangeCorrelationDataDescription.DataSource); instanceCorrelationData = correlationData; } return((T)(object)correlationData); } return(context.GetInnerProperty <T>()); }
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); }
public override T GetProperty <T>(BindingContext context) where T : class { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if ((typeof(T) == typeof(ChannelProtectionRequirements)) && (this.ProtectionLevel != System.Net.Security.ProtectionLevel.None)) { ChannelProtectionRequirements innerProperty = context.GetInnerProperty <ChannelProtectionRequirements>(); if (innerProperty == null) { return((T)ContextMessageHeader.GetChannelProtectionRequirements(this.ProtectionLevel)); } ChannelProtectionRequirements requirements2 = new ChannelProtectionRequirements(innerProperty); requirements2.Add(ContextMessageHeader.GetChannelProtectionRequirements(this.ProtectionLevel)); return((T)requirements2); } if (typeof(T) == typeof(IContextSessionProvider)) { return((T)this); } if (typeof(T) == typeof(IContextBindingElement)) { return((T)this); } if (!(typeof(T) == typeof(ICorrelationDataSource))) { return(context.GetInnerProperty <T>()); } ICorrelationDataSource instanceCorrelationData = this.instanceCorrelationData; if (instanceCorrelationData == null) { instanceCorrelationData = CorrelationDataSourceHelper.Combine(context.GetInnerProperty <ICorrelationDataSource>(), ContextExchangeCorrelationDataDescription.DataSource); this.instanceCorrelationData = instanceCorrelationData; } return((T)instanceCorrelationData); }
protected override void OnWriteAddressHeaderContents(XmlDictionaryWriter writer) { ContextMessageHeader.WriteHeaderContents(writer, this.context); }