private void CreateTransportManagers() { Collection<HostedHttpTransportManager> collection = new Collection<HostedHttpTransportManager>(); foreach (string str in HostedTransportConfigurationManager.MetabaseSettings.GetBindings(base.Scheme)) { BaseUriWithWildcard listenAddress = BaseUriWithWildcard.CreateHostedUri(base.Scheme, str, HostingEnvironmentWrapper.ApplicationVirtualPath); bool flag = false; if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { listenAddress = new BaseUriWithWildcard(listenAddress.BaseAddress, HostNameComparisonMode.WeakWildcard); flag = true; } HostedHttpTransportManager item = this.CreateTransportManager(listenAddress); if (item != null) { collection.Add(item); base.ListenAddresses.Add(listenAddress); } if (flag) { break; } } this.transportManagerDirectory = collection; }
public HostedNamedPipeTransportManager(BaseUriWithWildcard baseAddress) : base(baseAddress.BaseAddress) { this.HostNameComparisonMode = baseAddress.HostNameComparisonMode; this.onViaCallback = new Action<Uri>(OnVia); this.onDuplicatedViaCallback = new Func<Uri, int>(OnDuplicatedVia); }
public bool TryLookupUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, out TItem item) { BaseUriWithWildcard key = new BaseUriWithWildcard(uri, hostNameComparisonMode); if (TryCacheLookup(key, out item)) { return(item != null); } lock (ThisLock) { // exact match failed, perform the full lookup (which will also // catch case-insensitive variations that aren't yet in our cache) bool dummy; SegmentHierarchyNode <TItem> node = FindDataNode( UriSegmenter.ToPath(key.BaseAddress, hostNameComparisonMode, this.includePortInComparison), out dummy); if (node != null) { item = node.Data; } // We want to cache both positive AND negative results AddToCache(key, item); return(item != null); } }
private void AddToCache(BaseUriWithWildcard key, TItem item) { if (item == null) { } this.lookupCache.Add(key, (TItem)DBNull.Value); }
HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress) { UriPrefixTable<ITransportManagerRegistration> table = null; if (object.ReferenceEquals(this.Scheme, Uri.UriSchemeHttp)) { table = HttpChannelListener.StaticTransportManagerTable; } else { table = SharedHttpsTransportManager.StaticTransportManagerTable; } HostedHttpTransportManager httpManager = null; lock (table) { ITransportManagerRegistration registration; if (!table.TryLookupUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, out registration)) { httpManager = new HostedHttpTransportManager(listenAddress); table.RegisterUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, httpManager); } } return httpManager; }
private bool TryCacheLookup(BaseUriWithWildcard key, out TItem item) { object obj2 = this.lookupCache.GetValue(this.ThisLock, key); item = (obj2 == DBNull.Value) ? default(TItem) : ((TItem)obj2); return(obj2 != null); }
void AddToCache(BaseUriWithWildcard key, TItem item) { // Don't allow explicitly adding DBNulls. Fx.Assert(item != DBNull.Value, "Can't add DBNull to UriPrefixTable."); // HopperCache uses null as 'doesn't exist', so use DBNull as a stand-in for null. this.lookupCache.Add(key, item ?? (object)DBNull.Value); }
bool TryCacheLookup(BaseUriWithWildcard key, out TItem item) { object value = this.lookupCache.GetValue(ThisLock, key); // We might return null and true in the case of DBNull (cached negative result). // When TItem is object, the cast isn't sufficient to ---- out DBNulls, so we need an explicit check. item = value == DBNull.Value ? null : (TItem)value; return(value != null); }
internal SharedConnectionListener(BaseUriWithWildcard baseAddress, int queueId, Guid token, Func<Uri, int> onDuplicatedViaCallback) { this.baseAddress = baseAddress; this.queueId = queueId; this.token = token; this.onDuplicatedViaCallback = onDuplicatedViaCallback; this.connectionQueue = TraceUtility.CreateInputQueue<DuplicateConnectionAsyncResult>(); this.state = CommunicationState.Created; this.reconnectEvent = new ManualResetEvent(true); this.StartListen(false); }
public SharedListenerProxy(SharedConnectionListener parent) { this.parent = parent; this.baseAddress = parent.baseAddress; this.queueId = parent.queueId; this.token = parent.token; this.onDuplicatedViaCallback = parent.onDuplicatedViaCallback; this.isTcp = parent.baseAddress.BaseAddress.Scheme.Equals(Uri.UriSchemeNetTcp); this.securityEventName = Guid.NewGuid().ToString(); this.serviceName = SharedConnectionListener.GetServiceName(this.isTcp); }
internal SharedConnectionListener(BaseUriWithWildcard baseAddress, int queueId, Guid token, Func <Uri, int> onDuplicatedViaCallback) { this.baseAddress = baseAddress; this.queueId = queueId; this.token = token; this.onDuplicatedViaCallback = onDuplicatedViaCallback; this.connectionQueue = TraceUtility.CreateInputQueue <DuplicateConnectionAsyncResult>(); this.state = CommunicationState.Created; this.reconnectEvent = new ManualResetEvent(true); this.StartListen(false); }
public bool IsRegistered(BaseUriWithWildcard key) { bool flag; SegmentHierarchyNode <TItem> node; string[] path = UriSegmenter <TItem> .ToPath(key.BaseAddress, key.HostNameComparisonMode, this.includePortInComparison); lock (this.ThisLock) { node = this.FindDataNode(path, out flag); } return((flag && (node != null)) && (node.Data != null)); }
protected override void OnOpening() { base.OnOpening(); if (this.HostedVirtualPath != null) { BaseUriWithWildcard baseUri = AspNetEnvironment.Current.GetBaseUri(this.Scheme, this.Uri); if (baseUri != null) { this.hostNameComparisonMode = baseUri.HostNameComparisonMode; } } this.bufferManager = System.ServiceModel.Channels.BufferManager.CreateBufferManager(this.MaxBufferPoolSize, this.GetMaxBufferSize()); }
internal void OnOpenInternal(int queueId, Guid token) { lock (base.ThisLock) { this.queueId = queueId; this.token = token; BaseUriWithWildcard baseAddress = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode); if (this.onDuplicatedViaCallback == null) { this.onDuplicatedViaCallback = new Func <Uri, int>(this.OnDuplicatedVia); } this.listener = new SharedConnectionListener(baseAddress, queueId, token, this.onDuplicatedViaCallback); } }
public override bool Equals(object o) { BaseUriWithWildcard wildcard = o as BaseUriWithWildcard; if (((wildcard == null) || (wildcard.hashCode != this.hashCode)) || ((wildcard.hostNameComparisonMode != this.hostNameComparisonMode) || (wildcard.comparand.Port != this.comparand.Port))) { return(false); } if (!object.ReferenceEquals(wildcard.comparand.Scheme, this.comparand.Scheme)) { return(false); } return(this.comparand.Address.Equals(wildcard.comparand.Address)); }
public void RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item) { lock (this.ThisLock) { this.ClearCache(); BaseUriWithWildcard baseUri = new BaseUriWithWildcard(uri, hostNameComparisonMode); SegmentHierarchyNode <TItem> node = this.FindOrCreateNode(baseUri); if (node.Data != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("DuplicateRegistration", new object[] { uri }))); } node.SetData(item, baseUri); this.count++; } }
public override bool Equals(object o) { BaseUriWithWildcard other = o as BaseUriWithWildcard; if (other == null || other.hashCode != this.hashCode || other.hostNameComparisonMode != this.hostNameComparisonMode || other.comparand.Port != this.comparand.Port) { return(false); } if (!object.ReferenceEquals(other.comparand.Scheme, this.comparand.Scheme)) { return(false); } return(this.comparand.Address.Equals(other.comparand.Address)); }
public bool IsRegistered(BaseUriWithWildcard key) { Uri uri = key.BaseAddress; // don't need to normalize path since SegmentHierarchyNode is // already OrdinalIgnoreCase string[] paths = UriSegmenter.ToPath(uri, key.HostNameComparisonMode, this.includePortInComparison); bool exactMatch; SegmentHierarchyNode <TItem> node; lock (ThisLock) { node = FindDataNode(paths, out exactMatch); } return(exactMatch && node != null && node.Data != null); }
TransportListener(BaseUriWithWildcard pipeUri) { if (TD.PipeTransportListenerListeningStartIsEnabled()) { TD.PipeTransportListenerListeningStart(this.EventTraceActivity, (pipeUri.BaseAddress != null) ? pipeUri.BaseAddress.ToString() : string.Empty); } transportType = TransportType.NamedPipe; IConnectionListener connectionListener = new PipeConnectionListener(pipeUri.BaseAddress, pipeUri.HostNameComparisonMode, ListenerConstants.SharedConnectionBufferSize, null, false, int.MaxValue); demuxer = Go(connectionListener); if (TD.PipeTransportListenerListeningStopIsEnabled()) { TD.PipeTransportListenerListeningStop(this.EventTraceActivity); } }
private SegmentHierarchyNode <TItem> FindOrCreateNode(BaseUriWithWildcard baseUri) { string[] strArray = UriSegmenter <TItem> .ToPath(baseUri.BaseAddress, baseUri.HostNameComparisonMode, this.includePortInComparison); SegmentHierarchyNode <TItem> root = this.root; for (int i = 0; i < strArray.Length; i++) { SegmentHierarchyNode <TItem> node2; if (!root.TryGetChild(strArray[i], out node2)) { node2 = new SegmentHierarchyNode <TItem>(strArray[i], this.useWeakReferences); root.SetChildNode(strArray[i], node2); } root = node2; } return(root); }
SegmentHierarchyNode <TItem> FindOrCreateNode(BaseUriWithWildcard baseUri) { Fx.Assert(baseUri != null, "FindOrCreateNode: baseUri is null"); string[] path = UriSegmenter.ToPath(baseUri.BaseAddress, baseUri.HostNameComparisonMode, this.includePortInComparison); SegmentHierarchyNode <TItem> current = this.root; for (int i = 0; i < path.Length; ++i) { SegmentHierarchyNode <TItem> next; if (!current.TryGetChild(path[i], out next)) { next = new SegmentHierarchyNode <TItem>(path[i], useWeakReferences); current.SetChildNode(path[i], next); } current = next; } return(current); }
public void SetData(TData data, BaseUriWithWildcard path) { this.path = path; if (this.useWeakReferences) { if (data == null) { this.weakData = null; } else { this.weakData = new WeakReference(data); } } else { this.data = data; } }
protected override void OnOpening() { base.OnOpening(); // This check is necessary to avoid that the HostNameComparisonMode from the IIS listener address // is copied in an ASP-Net hosted environment when the IIS hosted service acts as client of another destination service // (for example using WSDualHttpBinding in a routing service) if (this.HostedVirtualPath != null) { // Copy the HostNameComparisonMode if necessary BaseUriWithWildcard baseAddress = AspNetEnvironment.Current.GetBaseUri(this.Scheme, this.Uri); if (baseAddress != null) { this.hostNameComparisonMode = baseAddress.HostNameComparisonMode; } } this.bufferManager = BufferManager.CreateBufferManager(MaxBufferPoolSize, GetMaxBufferSize()); }
internal void OnOpenInternal(int queueId, Guid token) { lock (ThisLock) { this.queueId = queueId; this.token = token; BaseUriWithWildcard path = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode); if (this.onDuplicatedViaCallback == null) { this.onDuplicatedViaCallback = new Func <Uri, int>(OnDuplicatedVia); } listener = new SharedConnectionListener(path, queueId, token, this.onDuplicatedViaCallback); // Delay the creation of the demuxer on the first request. } }
public bool TryLookupUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, out TItem item) { BaseUriWithWildcard key = new BaseUriWithWildcard(uri, hostNameComparisonMode); if (this.TryCacheLookup(key, out item)) { return(((TItem)item) != null); } lock (this.ThisLock) { bool flag; SegmentHierarchyNode <TItem> node = this.FindDataNode(UriSegmenter <TItem> .ToPath(key.BaseAddress, hostNameComparisonMode, this.includePortInComparison), out flag); if (node != null) { item = node.Data; } this.AddToCache(key, item); return(((TItem)item) != null); } }
public void RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item) { Fx.Assert(HostNameComparisonModeHelper.IsDefined(hostNameComparisonMode), "RegisterUri: Invalid HostNameComparisonMode value passed in."); lock (ThisLock) { // Since every newly registered Uri could alter what Prefixes should have matched, we // should clear the cache of any existing results and start over ClearCache(); BaseUriWithWildcard key = new BaseUriWithWildcard(uri, hostNameComparisonMode); SegmentHierarchyNode <TItem> node = FindOrCreateNode(key); if (node.Data != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString( SR.DuplicateRegistration, uri))); } node.SetData(item, key); count++; } }
private HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress) { UriPrefixTable<ITransportManagerRegistration> staticTransportManagerTable = null; if (object.ReferenceEquals(base.Scheme, Uri.UriSchemeHttp)) { staticTransportManagerTable = HttpChannelListener.StaticTransportManagerTable; } else { staticTransportManagerTable = SharedHttpsTransportManager.StaticTransportManagerTable; } HostedHttpTransportManager item = null; lock (staticTransportManagerTable) { ITransportManagerRegistration registration; if (!staticTransportManagerTable.TryLookupUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, out registration)) { item = new HostedHttpTransportManager(listenAddress); staticTransportManagerTable.RegisterUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, item); } } return item; }
void CreateTransportManagers() { Collection<HostedHttpTransportManager> tempDirectory = new Collection<HostedHttpTransportManager>(); string[] bindings = HostedTransportConfigurationManager.MetabaseSettings.GetBindings(this.Scheme); foreach (string binding in bindings) { TryDebugPrint("HttpHostedTransportConfiguration.CreateTransportManagers() adding binding: " + binding); BaseUriWithWildcard listenAddress = BaseUriWithWildcard.CreateHostedUri(this.Scheme, binding, HostingEnvironmentWrapper.ApplicationVirtualPath); bool done = false; if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { //In this specific mode we only create one transport manager and all the //hosted channel listeners hang off of this transport manager listenAddress = new BaseUriWithWildcard(listenAddress.BaseAddress, HostNameComparisonMode.WeakWildcard); done = true; } HostedHttpTransportManager httpManager = CreateTransportManager(listenAddress); //httpManager will be null when 2 site bindings differ only in ip address if (httpManager != null) { tempDirectory.Add(httpManager); ListenAddresses.Add(listenAddress); } if (done) { break; } } transportManagerDirectory = tempDirectory; }
bool RegisterBindings(IActivatedMessageQueue queue, int siteId, string[] bindings, string path) { Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() bindings#: " + bindings.Length); BaseUriWithWildcard[] baseAddresses = new BaseUriWithWildcard[bindings.Length]; // first make sure all the bindings are valid for this protocol for (int i = 0; i < bindings.Length; i++) { string binding = bindings[i]; int index = binding.IndexOf(':'); string protocol = binding.Substring(0, index); if (string.Compare(this.ProtocolName, protocol, StringComparison.OrdinalIgnoreCase) != 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.LAProtocolMismatch, protocol, path, this.ProtocolName))); } binding = binding.Substring(index + 1); try { baseAddresses[i] = BaseUriWithWildcard.CreateHostedUri(ProtocolName, binding, path); Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() CreateUrlFromBinding(binding: " + binding + " path: " + path + ") returned baseAddress: " + baseAddresses[i]); } catch (UriFormatException exception) { Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() CreateUrlFromBinding(binding: " + binding + " path: " + path + ") failed with UriFormatException: " + exception.Message); DiagnosticUtility.TraceHandledException(exception, TraceEventType.Error); // We only log the event for the site root. if (string.Compare(path, SiteRootPath, StringComparison.OrdinalIgnoreCase) == 0) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)EventLogCategory.ListenerAdapter, (uint)EventLogEventId.BindingError, protocol, binding, siteId.ToString(NumberFormatInfo.CurrentInfo), bindings[i], ListenerTraceUtility.CreateSourceString(this), exception.ToString()); } return false; } } // now make sure all the bindings can be listened on or roll back for (int i = 0; i < bindings.Length; i++) { ListenerExceptionStatus status = ListenerExceptionStatus.FailedToListen; Exception exception = null; try { status = queue.Register(baseAddresses[i]); Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() registering baseAddress: " + baseAddresses[i] + " with queue returned: " + status); } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } DiagnosticUtility.TraceHandledException(exception, TraceEventType.Error); exception = ex; } if (status != ListenerExceptionStatus.Success) { // We only log the event for the site root. if (string.Compare(path, SiteRootPath, StringComparison.OrdinalIgnoreCase) == 0) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)EventLogCategory.ListenerAdapter, (uint)EventLogEventId.LAFailedToListenForApp, activationService.ActivationServiceName, ProtocolName, siteId.ToString(NumberFormatInfo.CurrentInfo), baseAddresses[i].ToString(), status.ToString(), exception == null ? string.Empty : exception.ToString()); } queue.UnregisterAll(); return false; } } return true; }
internal void OnOpenInternal(int queueId, Guid token) { lock (base.ThisLock) { this.queueId = queueId; this.token = token; BaseUriWithWildcard baseAddress = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode); if (this.onDuplicatedViaCallback == null) { this.onDuplicatedViaCallback = new Func<Uri, int>(this.OnDuplicatedVia); } this.listener = new SharedConnectionListener(baseAddress, queueId, token, this.onDuplicatedViaCallback); } }
public SharedListenerProxy(SharedConnectionListener parent) { this.parent = parent; this.baseAddress = parent.baseAddress; this.queueId = parent.queueId; this.token = parent.token; this.onDuplicatedViaCallback = parent.onDuplicatedViaCallback; this.isTcp = parent.baseAddress.BaseAddress.Scheme.Equals(Uri.UriSchemeNetTcp); this.securityEventName = Guid.NewGuid().ToString(); this.serviceName = SharedConnectionListener.GetServiceName(this.isTcp); }
public HostedTcpTransportManager(BaseUriWithWildcard baseAddress) : base(baseAddress.BaseAddress) { base.HostNameComparisonMode = baseAddress.HostNameComparisonMode; this.onViaCallback = new Action<Uri>(this.OnVia); }
internal void OnOpenInternal(int queueId, Guid token) { lock (ThisLock) { this.queueId = queueId; this.token = token; BaseUriWithWildcard path = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode); if (this.onDuplicatedViaCallback == null) { this.onDuplicatedViaCallback = new Func<Uri, int>(OnDuplicatedVia); } listener = new SharedConnectionListener(path, queueId, token, this.onDuplicatedViaCallback); // Delay the creation of the demuxer on the first request. } }
internal static void Stop(BaseUriWithWildcard pipeUri) { lock (namedPipeInstances) { TransportListener t = namedPipeInstances[pipeUri] as TransportListener; if (t != null) { if (DiagnosticUtility.ShouldTraceInformation) { ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.TransportListenerStop, SR.GetString(SR.TraceCodeTransportListenerStop), t); } try { t.Stop(); } finally { namedPipeInstances.Remove(pipeUri); } } } }
internal static void Stop(MessageQueue messageQueue, BaseUriWithWildcard path) { if (messageQueue.TransportType == TransportType.Tcp) { IPEndPoint endPoint = GetEndPoint(path.BaseAddress); TransportListener.Stop(endPoint); tcpMessageQueues.UnregisterUri(path.BaseAddress, path.HostNameComparisonMode); } else { TransportListener.Stop(path); namedPipeMessageQueues.UnregisterUri(path.BaseAddress, path.HostNameComparisonMode); } }
private void OnOpenInternal(int queueId, Guid token) { lock (base.ThisLock) { this.queueId = queueId; this.token = token; BaseUriWithWildcard baseAddress = new BaseUriWithWildcard(base.ListenUri, base.HostNameComparisonMode); this.listener = new SharedConnectionListener(baseAddress, queueId, token, this.onDuplicatedViaCallback); } }
void Unregister(BaseUriWithWildcard path) { Fx.Assert(paths.Contains(path), "Unregister: unregistering an unregistered path"); if (DiagnosticUtility.ShouldTraceInformation) { ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.MessageQueueUnregisterSucceeded, SR.GetString(SR.TraceCodeMessageQueueUnregisterSucceeded), new StringTraceRecord("Path", path.ToString()), this, null); } if (TD.MessageQueueUnregisterSucceededIsEnabled()) { TD.MessageQueueUnregisterSucceeded(this.EventTraceActivity, path.ToString()); } RoutingTable.Stop(this, path); IncrementUrisUnregisteredCounters(); OnUnregisterCompleted(); registry.Remove(path); paths.Remove(path); }
internal static ListenerExceptionStatus Register(BaseUriWithWildcard path, WorkerProcess worker) { MessageQueue queue = null; lock (registry) { if (registry.TryGetValue(path, out queue)) { if (!queue.CanShare) { return ListenerExceptionStatus.ConflictingRegistration; } } else { queue = new MessageQueue(); ListenerExceptionStatus status = ListenerExceptionStatus.FailedToListen; try { status = queue.Register(path); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (DiagnosticUtility.ShouldTraceError) { ListenerTraceUtility.TraceEvent(TraceEventType.Error, ListenerTraceCode.RoutingTableCannotListen, SR.GetString(SR.TraceCodeRoutingTableCannotListen), new StringTraceRecord("Path", path.ToString()), null, exception); } } if (status != ListenerExceptionStatus.Success) { // not setting the worker.queue is not a problem, since we can't use this WorkerProcess return status; } registry.Add(path, queue); } } queue.OnNewWorkerAvailable(worker); return ListenerExceptionStatus.Success; }
public ListenerExceptionStatus Register(BaseUriWithWildcard path) { if (path.BaseAddress.Scheme == Uri.UriSchemeNetTcp) { if (transportType == TransportType.NamedPipe) { return ListenerExceptionStatus.ProtocolUnsupported; } maxQueueSize = ListenerConfig.NetTcp.MaxPendingConnections; transportType = TransportType.Tcp; } else if (path.BaseAddress.Scheme == Uri.UriSchemeNetPipe) { if (transportType == TransportType.Tcp) { return ListenerExceptionStatus.ProtocolUnsupported; } maxQueueSize = ListenerConfig.NetPipe.MaxPendingConnections; transportType = TransportType.NamedPipe; } else { return ListenerExceptionStatus.ProtocolUnsupported; } ListenerExceptionStatus status = RoutingTable.Start(this, path); if (status == ListenerExceptionStatus.Success) { paths.Add(path); IncrementUrisRegisteredCounters(); OnRegisterCompleted(); } return status; }
void OnOpenInternal(int queueId, Guid token) { lock (ThisLock) { this.queueId = queueId; this.token = token; BaseUriWithWildcard path = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode); listener = new SharedConnectionListener(path, queueId, token, this.onDuplicatedViaCallback); } }
ListenerExceptionStatus IConnectionRegister.Register(Version version, int processId, BaseUriWithWildcard path, int queueId, Guid token, string eventName) { if (TD.MessageQueueRegisterStartIsEnabled()) { TD.MessageQueueRegisterStart(this.EventTraceActivity); } Debug.Print("WorkerProcess.Register() version: " + version + " processId: " + processId + " path: " + path + " queueId: " + queueId + " token: " + token + " eventName: " + eventName); if (DiagnosticUtility.ShouldTraceInformation) { ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.MessageQueueRegisterCalled, SR.GetString(SR.TraceCodeMessageQueueRegisterCalled), new StringTraceRecord("Path", path.ToString()), this, null); } // Get the callback channel this.connectionDuplicator = OperationContext.Current.GetCallbackChannel<IConnectionDuplicator>(); // Prevent this duplicate operation from timing out, faulting the pipe, and stopping any further communication with w3wp // we're gated by MaxPendingAccepts + MaxPendingConnection. see CSD Main bug 193390 for details ((IContextChannel)this.connectionDuplicator).OperationTimeout = TimeSpan.MaxValue; ListenerExceptionStatus status = ListenerExceptionStatus.Success; bool abortInstance = false; if (path == null || eventName == null) { status = ListenerExceptionStatus.InvalidArgument; abortInstance = true; goto FAILED; } // Vista only: validate remote process ID if (OSEnvironmentHelper.IsVistaOrGreater) { status = ListenerExceptionStatus.InvalidArgument; object property = OperationContext.Current.IncomingMessage.Properties[ConnectionMessageProperty.Name]; Fx.Assert(property != null, "WorkerProcess.Register() ConnectionMessageProperty not found!"); IConnection connection = property as IConnection; Fx.Assert(connection != null, "WorkerProcess.Register() ConnectionMessageProperty is not IConnection!"); PipeHandle pipe = connection.GetCoreTransport() as PipeHandle; Fx.Assert(pipe != null, "WorkerProcess.Register() CoreTransport is not PipeHandle!"); if (processId != pipe.GetClientPid()) { status = ListenerExceptionStatus.InvalidArgument; abortInstance = true; goto FAILED; } } // validate version Version ourVersion = Assembly.GetExecutingAssembly().GetName().Version; if (version > ourVersion) { // VERSIONING // in V1 we assume that we can handle earlier versions // this might not be true when we ship later releases. Debug.Print("WorkerProcess.Register() unsupported version ourVersion: " + ourVersion + " version: " + version); status = ListenerExceptionStatus.VersionUnsupported; goto FAILED; } if (queueId == 0 && path == null) { status = ListenerExceptionStatus.InvalidArgument; abortInstance = true; goto FAILED; } this.processId = processId; this.queueId = 0; if (queueId != 0) { this.queueId = queueId; status = ActivatedMessageQueue.Register(queueId, token, this); } else { status = MessageQueue.Register(path, this); } if (status == ListenerExceptionStatus.Success) { foreach (IChannel channel in OperationContext.Current.InstanceContext.IncomingChannels) { channel.Faulted += new EventHandler(WorkerProcess_Faulted); channel.Closed += new EventHandler(WorkerProcess_Closed); } try { using (EventWaitHandle securityEvent = EventWaitHandle.OpenExisting(ListenerConstants.GlobalPrefix + eventName, EventWaitHandleRights.Modify)) { securityEvent.Set(); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } DiagnosticUtility.TraceHandledException(exception, TraceEventType.Error); status = ListenerExceptionStatus.InvalidArgument; abortInstance = true; } } if (status != ListenerExceptionStatus.Success) { goto FAILED; } if (DiagnosticUtility.ShouldTraceInformation) { ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.MessageQueueRegisterSucceeded, SR.GetString(SR.TraceCodeMessageQueueRegisterSucceeded), new StringTraceRecord("Path", path.ToString()), this, null); } if (TD.MessageQueueRegisterCompletedIsEnabled()) { TD.MessageQueueRegisterCompleted(this.EventTraceActivity, path.ToString()); } FAILED: if (abortInstance) { if (DiagnosticUtility.ShouldTraceError) { ListenerTraceUtility.TraceEvent(TraceEventType.Error, ListenerTraceCode.MessageQueueRegisterFailed, SR.GetString(SR.TraceCodeMessageQueueRegisterFailed), new StringTraceRecord("Register", SR.GetString(SR.SharingRegistrationFailedAndAbort, status.ToString())), this, null); } if (TD.MessageQueueRegisterAbortIsEnabled()) { TD.MessageQueueRegisterAbort(this.EventTraceActivity, status.ToString(), (path != null) ? path.ToString() : string.Empty); } AbortServiceInstance(); } else if (status != ListenerExceptionStatus.Success) { if (DiagnosticUtility.ShouldTraceError) { ListenerTraceUtility.TraceEvent(TraceEventType.Error, ListenerTraceCode.MessageQueueRegisterFailed, SR.GetString(SR.TraceCodeMessageQueueRegisterFailed), new StringTraceRecord("Register", SR.GetString(SR.SharingRegistrationFailed, status.ToString())), this, null); } if (TD.MessageQueueRegisterFailedIsEnabled()) { TD.MessageQueueRegisterFailed(this.EventTraceActivity, (path != null) ? path.ToString() : string.Empty, status.ToString()); } InitiateClosingServiceInstance(); } return status; }
ListenerExceptionStatus IActivatedMessageQueue.Register(BaseUriWithWildcard url) { return base.Register(url); }
public ListenerExceptionStatus Register(BaseUriWithWildcard url) { this.activationService.Bindings.RegisterBindingFilterIfNecessary(url.BaseAddress.Host, this.filter); return ListenerExceptionStatus.Success; }
internal static ListenerExceptionStatus Start(MessageQueue messageQueue, BaseUriWithWildcard path) { if (messageQueue.TransportType == TransportType.Tcp) { return TcpStart(messageQueue, path); } else { return NamedPipeStart(messageQueue, path); } }
internal HostedHttpTransportManager(BaseUriWithWildcard baseAddress) : base(baseAddress.BaseAddress, baseAddress.HostNameComparisonMode) { base.IsHosted = true; }
static ListenerExceptionStatus TcpStart(MessageQueue messageQueue, BaseUriWithWildcard path) { int encodedSize = System.Text.Encoding.UTF8.GetByteCount(path.BaseAddress.AbsoluteUri); if (encodedSize > ListenerConstants.MaxUriSize) { if (DiagnosticUtility.ShouldTraceInformation) { ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.RoutingTablePathTooLong, SR.GetString(SR.TraceCodeRoutingTablePathTooLong), new StringTraceRecord("Path", path.ToString()), null, null); } return ListenerExceptionStatus.PathTooLong; } IPEndPoint endPoint = GetEndPoint(path.BaseAddress); lock (tcpMessageQueues) { if (tcpMessageQueues.IsRegistered(path)) { if (DiagnosticUtility.ShouldTraceInformation) { ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.RoutingTableNamespaceConflict, SR.GetString(SR.TraceCodeRoutingTableNamespaceConflict), new StringTraceRecord("Path", path.ToString()), null, null); } return ListenerExceptionStatus.ConflictingRegistration; } TransportListener.Listen(endPoint); tcpMessageQueues.RegisterUri(path.BaseAddress, path.HostNameComparisonMode, new MessageQueueAndPath(messageQueue, path.BaseAddress)); } if (DiagnosticUtility.ShouldTraceInformation) { ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.RoutingTableRegisterSuccess, SR.GetString(SR.TraceCodeRoutingTableRegisterSuccess), new StringTraceRecord("Path", path.ToString()), null, null); } return ListenerExceptionStatus.Success; }
internal static void Listen(BaseUriWithWildcard pipeUri) { lock (namedPipeInstances) { if (namedPipeInstances.ContainsKey(pipeUri)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.PipeAddressAlreadyUsed))); } else { TransportListener t = new TransportListener(pipeUri); namedPipeInstances.Add(pipeUri, t); } } }