Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / SMSvcHost / System / ServiceModel / Activation / ListenerAdapterBase.cs / 1 / ListenerAdapterBase.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Activation { using System; using System.ComponentModel; using System.Diagnostics; using System.Reflection; using System.Runtime.InteropServices; using System.Security.Principal; using System.ServiceModel; using System.Threading; using System.ServiceModel.Diagnostics; using System.Globalization; using System.ServiceModel.Activation.Diagnostics; abstract class ListenerAdapterBase { WebHostUnsafeNativeMethods.WebhostListenerCallbacks listenerCallbacks; int protocolHandle = 0; int closed; protected string protocolName = null; const int WebhostMajorVersion = 7; const int WebhostMinorVersion = 0; static WebHostUnsafeNativeMethods.SafeFreeLibrary webHostIpm; static WebHostUnsafeNativeMethods.WebhostGetVersion webhostGetVersion; static WebHostUnsafeNativeMethods.WebhostRegisterProtocol webhostRegisterProtocol; static WebHostUnsafeNativeMethods.WebhostOpenListenerChannelInstance webhostOpenListenerChannelInstance; static WebHostUnsafeNativeMethods.WebhostCloseAllListenerChannelInstances webhostCloseAllListenerChannelInstances; static WebHostUnsafeNativeMethods.WebhostUnregisterProtocol webhostUnregisterProtocol; static ListenerAdapterBase() { #pragma warning suppress 56523 // [....], the Win32Exception ctor calls Marshal.GetLastWin32Error webHostIpm = WebHostUnsafeNativeMethods.LoadLibraryEx(SMSvcHost.ListenerAdapterNativeLibrary, IntPtr.Zero, WebHostUnsafeNativeMethods.LOAD_WITH_ALTERED_SEARCH_PATH); if (webHostIpm.IsInvalid) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception()); } webhostGetVersion = (WebHostUnsafeNativeMethods.WebhostGetVersion)GetProcDelegate(webHostIpm, "WebhostGetVersion"); webhostRegisterProtocol = (WebHostUnsafeNativeMethods.WebhostRegisterProtocol)GetProcDelegate (webHostIpm, "WebhostRegisterProtocol"); webhostUnregisterProtocol = (WebHostUnsafeNativeMethods.WebhostUnregisterProtocol)GetProcDelegate (webHostIpm, "WebhostUnregisterProtocol"); webhostOpenListenerChannelInstance = (WebHostUnsafeNativeMethods.WebhostOpenListenerChannelInstance)GetProcDelegate (webHostIpm, "WebhostOpenListenerChannelInstance"); webhostCloseAllListenerChannelInstances = (WebHostUnsafeNativeMethods.WebhostCloseAllListenerChannelInstances)GetProcDelegate (webHostIpm, "WebhostCloseAllListenerChannelInstances"); } protected ListenerAdapterBase(string protocolName) { if (string.IsNullOrEmpty(protocolName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("protocolName")); } this.protocolName = protocolName; listenerCallbacks = new WebHostUnsafeNativeMethods.WebhostListenerCallbacks(); listenerCallbacks.dwBytesInCallbackStructure = Marshal.SizeOf(listenerCallbacks); listenerCallbacks.webhostListenerConfigManagerConnected = new WebHostUnsafeNativeMethods.WebhostListenerConfigManagerConnected(onConfigManagerConnected); listenerCallbacks.webhostListenerConfigManagerDisconnected = new WebHostUnsafeNativeMethods.WebhostListenerConfigManagerDisconnected(onConfigManagerDisconnected); listenerCallbacks.webhostListenerConfigManagerInitializationCompleted = new WebHostUnsafeNativeMethods.WebhostListenerConfigManagerInitializationCompleted(onConfigManagerInitializationCompleted); listenerCallbacks.webhostListenerApplicationPoolCreated = new WebHostUnsafeNativeMethods.WebhostListenerApplicationPoolCreated(onApplicationPoolCreated); listenerCallbacks.webhostListenerApplicationPoolDeleted = new WebHostUnsafeNativeMethods.WebhostListenerApplicationPoolDeleted(onApplicationPoolDeleted); listenerCallbacks.webhostListenerApplicationPoolIdentityChanged = new WebHostUnsafeNativeMethods.WebhostListenerApplicationPoolIdentityChanged(onApplicationPoolIdentityChanged); listenerCallbacks.webhostListenerApplicationPoolStateChanged = new WebHostUnsafeNativeMethods.WebhostListenerApplicationPoolStateChanged(onApplicationPoolStateChanged); listenerCallbacks.webhostListenerApplicationPoolCanOpenNewListenerChannelInstance = new WebHostUnsafeNativeMethods.WebhostListenerApplicationPoolCanOpenNewListenerChannelInstance(onApplicationPoolCanLaunchQueueInstance); listenerCallbacks.webhostListenerApplicationPoolAllListenerChannelInstancesStopped = new WebHostUnsafeNativeMethods.WebhostListenerApplicationPoolAllListenerChannelInstancesStopped(onApplicationPoolAllQueueInstancesStopped); listenerCallbacks.webhostListenerApplicationCreated = new WebHostUnsafeNativeMethods.WebhostListenerApplicationCreated(onApplicationCreated); listenerCallbacks.webhostListenerApplicationDeleted = new WebHostUnsafeNativeMethods.WebhostListenerApplicationDeleted(onApplicationDeleted); listenerCallbacks.webhostListenerApplicationBindingsChanged = new WebHostUnsafeNativeMethods.WebhostListenerApplicationBindingsChanged(onApplicationBindingsChanged); listenerCallbacks.webhostListenerApplicationAppPoolChanged = new WebHostUnsafeNativeMethods.WebhostListenerApplicationAppPoolChanged(onApplicationAppPoolChanged); listenerCallbacks.webhostListenerApplicationRequestsBlockedChanged = new WebHostUnsafeNativeMethods.WebhostListenerApplicationRequestsBlockedChanged(onApplicationRequestsBlockedChanged); } static Delegate GetProcDelegate (WebHostUnsafeNativeMethods.SafeFreeLibrary library, string procName) { #pragma warning suppress 56523 // [....], the Win32Exception ctor calls Marshal.GetLastWin32Error IntPtr funcPtr = WebHostUnsafeNativeMethods.GetProcAddress(library, procName); if (funcPtr == IntPtr.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(SR.GetString(SR.WebHostProcNotFound, procName, SMSvcHost.ListenerAdapterNativeLibrary))); } return Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(TDelegate)); } protected string[] ParseBindings(IntPtr bindingsMultiSz, int numberOfBindings) { if (bindingsMultiSz == IntPtr.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bindingsMultiSz")); } if (numberOfBindings < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException("numberOfBindings")); } string[] bindings = new string[numberOfBindings]; unsafe { ushort* bindingsBufferPtr = (ushort*)bindingsMultiSz; for (int i = 0; i < numberOfBindings; i++) { string bindingString = Marshal.PtrToStringUni((IntPtr)bindingsBufferPtr); if (string.IsNullOrEmpty(bindingString)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException("bindingsMultiSz")); } bindings[i] = bindingString; bindingsBufferPtr += bindingString.Length + 1; } } return bindings; } void onApplicationAppPoolChanged(IntPtr context, string appKey, string appPoolId) { this.OnApplicationAppPoolChanged(appKey, appPoolId); } protected abstract void OnApplicationAppPoolChanged(string appKey, string appPoolId); void onApplicationBindingsChanged(IntPtr context, string appKey, IntPtr bindingsMultiSz, int numberOfBindings) { this.OnApplicationBindingsChanged(appKey, bindingsMultiSz, numberOfBindings); } protected abstract void OnApplicationBindingsChanged(string appKey, IntPtr bindingsMultiSz, int numberOfBindings); void onApplicationCreated(IntPtr context, string appKey, string path, int siteId, string appPoolId, IntPtr bindingsMultiSz, int numberOfBindings, bool requestsBlocked) { this.OnApplicationCreated(appKey, path, siteId, appPoolId, bindingsMultiSz, numberOfBindings, requestsBlocked); } protected abstract void OnApplicationCreated(string appKey, string path, int siteId, string appPoolId, IntPtr bindingsMultiSz, int numberOfBindings, bool requestsBlocked); void onApplicationDeleted(IntPtr context, string appKey) { this.OnApplicationDeleted(appKey); } protected abstract void OnApplicationDeleted(string appKey); void onApplicationPoolAllQueueInstancesStopped(IntPtr context, string appPoolId, int listenerChannelId) { this.OnApplicationPoolAllQueueInstancesStopped(appPoolId, listenerChannelId); } protected abstract void OnApplicationPoolAllQueueInstancesStopped(string appPoolId, int listenerChannelId); void onApplicationPoolCanLaunchQueueInstance(IntPtr context, string appPoolId, int listenerChannelId) { this.OnApplicationPoolCanLaunchQueueInstance(appPoolId, listenerChannelId); } protected abstract void OnApplicationPoolCanLaunchQueueInstance(string appPoolId, int listenerChannelId); void onApplicationPoolCreated(IntPtr context, string appPoolId, IntPtr sid) { this.OnApplicationPoolCreated(appPoolId, new SecurityIdentifier(sid)); } protected abstract void OnApplicationPoolCreated(string appPoolId, SecurityIdentifier sid); void onApplicationPoolDeleted(IntPtr context, string appPoolId) { this.OnApplicationPoolDeleted(appPoolId); } protected abstract void OnApplicationPoolDeleted(string appPoolId); void onApplicationPoolIdentityChanged(IntPtr context, string appPoolId, IntPtr sid) { this.OnApplicationPoolIdentityChanged(appPoolId, new SecurityIdentifier(sid)); } protected abstract void OnApplicationPoolIdentityChanged(string appPoolId, SecurityIdentifier sid); void onApplicationPoolStateChanged(IntPtr context, string appPoolId, bool isEnabled) { this.OnApplicationPoolStateChanged(appPoolId, isEnabled); } protected abstract void OnApplicationPoolStateChanged(string appPoolId, bool isEnabled); void onApplicationRequestsBlockedChanged(IntPtr context, string appKey, bool requestsBlocked) { this.OnApplicationRequestsBlockedChanged(appKey, requestsBlocked); } protected abstract void OnApplicationRequestsBlockedChanged(string appKey, bool requestsBlocked); void onConfigManagerConnected(IntPtr context) { this.OnConfigManagerConnected(); } protected abstract void OnConfigManagerConnected(); void onConfigManagerDisconnected(IntPtr context, int hresult) { this.OnConfigManagerDisconnected(hresult); } protected abstract void OnConfigManagerDisconnected(int hresult); void onConfigManagerInitializationCompleted(IntPtr context) { this.OnConfigManagerInitializationCompleted(); } protected abstract void OnConfigManagerInitializationCompleted(); protected void Close() { if (Interlocked.Increment(ref closed) > 1) { return; } int hresult = webhostUnregisterProtocol(protocolHandle); if (hresult != 0) { if (DiagnosticUtility.ShouldTraceError) { ListenerTraceUtility.TraceEvent(TraceEventType.Error, TraceCode.WasWebHostAPIFailed, new StringTraceRecord("HRESULT", SR.GetString(SR.TraceCodeWasWebHostAPIFailed, "WebhostUnregisterProtocol", hresult.ToString(CultureInfo.CurrentCulture))), this, null); } } } protected int OpenListenerChannelInstance(string appPoolId, int listenerChannelId, byte[] queueBlob) { DiagnosticUtility.DebugAssert(appPoolId != null, ""); int queueBlobLength = (queueBlob != null) ? queueBlob.Length : 0; return webhostOpenListenerChannelInstance(protocolHandle, appPoolId, listenerChannelId, queueBlob, queueBlobLength); } internal virtual void Open() { int major, minor; int hresult = webhostGetVersion(out major, out minor); if (hresult != 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(hresult)); } if (major != WebhostMajorVersion || minor != WebhostMinorVersion) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new PlatformNotSupportedException( SR.GetString(SR.WebHostVersionMismatch, WebhostMajorVersion, WebhostMinorVersion, major, minor))); } hresult = webhostRegisterProtocol(protocolName, ref listenerCallbacks, IntPtr.Zero, out protocolHandle); if (hresult != 0 || protocolHandle == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(hresult)); } } protected int CloseAllListenerChannelInstances(string appPoolId, int listenerChannelId) { if (string.IsNullOrEmpty(appPoolId)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("appPoolId")); } return webhostCloseAllListenerChannelInstances(protocolHandle, appPoolId, listenerChannelId); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ProfileGroupSettings.cs
- DateTimeOffsetConverter.cs
- WorkflowShape.cs
- Point3DValueSerializer.cs
- _Events.cs
- TablePattern.cs
- SafeCryptContextHandle.cs
- WaitHandle.cs
- LineBreakRecord.cs
- panel.cs
- WebSysDescriptionAttribute.cs
- EventHandlers.cs
- StackBuilderSink.cs
- DataGridViewCellFormattingEventArgs.cs
- SapiAttributeParser.cs
- BinaryFormatterWriter.cs
- AssemblyBuilder.cs
- MobileTemplatedControlDesigner.cs
- ServiceModelPerformanceCounters.cs
- Stackframe.cs
- XmlSchemaChoice.cs
- IsolatedStorageFilePermission.cs
- ThemeDirectoryCompiler.cs
- ReverseComparer.cs
- XmlSerializerFactory.cs
- AssemblyAttributes.cs
- SqlBuffer.cs
- _OSSOCK.cs
- Geometry.cs
- RegexCode.cs
- InstanceNameConverter.cs
- MainMenu.cs
- IndividualDeviceConfig.cs
- InternalEnumValidator.cs
- BuildProviderAppliesToAttribute.cs
- InvokeHandlers.cs
- AudienceUriMode.cs
- WorkflowItemsPresenter.cs
- Util.cs
- DocumentOrderQuery.cs
- NameValuePair.cs
- Cast.cs
- ActivityValidator.cs
- RotateTransform3D.cs
- TabControl.cs
- WindowsListViewItem.cs
- XmlILAnnotation.cs
- CheckedListBox.cs
- ResourceManager.cs
- RightsManagementPermission.cs
- EmptyControlCollection.cs
- GeneralTransform.cs
- HttpProfileGroupBase.cs
- ConfigurationStrings.cs
- Utils.cs
- TypeDependencyAttribute.cs
- BaseResourcesBuildProvider.cs
- DATA_BLOB.cs
- MediaElement.cs
- IndexedString.cs
- MdiWindowListItemConverter.cs
- BindingGraph.cs
- OracleEncoding.cs
- SwitchAttribute.cs
- DomainUpDown.cs
- SctClaimDictionary.cs
- BaseInfoTable.cs
- MemoryFailPoint.cs
- UnsafeNativeMethods.cs
- Interlocked.cs
- ClockGroup.cs
- RectConverter.cs
- SafeBuffer.cs
- SqlFactory.cs
- ByteStreamGeometryContext.cs
- DesignerTextBoxAdapter.cs
- LinqDataSource.cs
- ContentElement.cs
- sqlpipe.cs
- MethodBuilder.cs
- DecimalAnimationUsingKeyFrames.cs
- InProcStateClientManager.cs
- Task.cs
- ZoomPercentageConverter.cs
- AssociationTypeEmitter.cs
- PeerToPeerException.cs
- SupportsPreviewControlAttribute.cs
- SoapFormatterSinks.cs
- ToolStripPanelRenderEventArgs.cs
- MetaData.cs
- Expander.cs
- SqlClientFactory.cs
- DiscoveryDocumentSearchPattern.cs
- DataGridView.cs
- CurrentChangingEventManager.cs
- ConfigXmlText.cs
- ControlParameter.cs
- CTreeGenerator.cs
- ResizeBehavior.cs
- MediaEntryAttribute.cs