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
- ToolStripProgressBar.cs
- ListControlConvertEventArgs.cs
- ObjectManager.cs
- XamlRtfConverter.cs
- ArithmeticException.cs
- LogFlushAsyncResult.cs
- EntityDataSourceDataSelection.cs
- GeometryGroup.cs
- RadioButton.cs
- JavaScriptString.cs
- DependencyObjectValidator.cs
- SortQuery.cs
- EntityDataSourceWrapperCollection.cs
- ParameterBuilder.cs
- UnsafeNativeMethods.cs
- ButtonColumn.cs
- WarningException.cs
- Encoder.cs
- MULTI_QI.cs
- PolicyDesigner.cs
- WindowsAltTab.cs
- ClientProxyGenerator.cs
- HtmlTableRow.cs
- SynchronizedInputProviderWrapper.cs
- PinnedBufferMemoryStream.cs
- BitmapEffectGeneralTransform.cs
- LayoutEvent.cs
- ClockController.cs
- AdornedElementPlaceholder.cs
- ViewStateModeByIdAttribute.cs
- InputReportEventArgs.cs
- login.cs
- ObjectStateManager.cs
- ExpanderAutomationPeer.cs
- GcHandle.cs
- EllipseGeometry.cs
- control.ime.cs
- UndoUnit.cs
- ListMarkerLine.cs
- AtlasWeb.Designer.cs
- SendMailErrorEventArgs.cs
- TemplatedWizardStep.cs
- TextTreeText.cs
- IPEndPoint.cs
- BlurBitmapEffect.cs
- login.cs
- DirectoryObjectSecurity.cs
- XmlUnspecifiedAttribute.cs
- StrokeCollectionConverter.cs
- TextEditorTables.cs
- MemberAccessException.cs
- basevalidator.cs
- LocalizationComments.cs
- ContractBase.cs
- MediaElementAutomationPeer.cs
- MediaElementAutomationPeer.cs
- ProjectionAnalyzer.cs
- BaseDataListDesigner.cs
- InProcStateClientManager.cs
- TableLayoutStyleCollection.cs
- AddingNewEventArgs.cs
- WriterOutput.cs
- ProcessStartInfo.cs
- EntityClassGenerator.cs
- ToolStripDesigner.cs
- DocumentGrid.cs
- CachingHintValidation.cs
- CodeMethodInvokeExpression.cs
- WebPartConnectionsConfigureVerb.cs
- ActivityExecutorDelegateInfo.cs
- ExceptionDetail.cs
- ListBoxItemWrapperAutomationPeer.cs
- HwndHostAutomationPeer.cs
- KerberosTicketHashIdentifierClause.cs
- StringWriter.cs
- ResXFileRef.cs
- ContextDataSourceView.cs
- XmlTextReader.cs
- DataBinding.cs
- _RequestLifetimeSetter.cs
- PerformanceCounterPermissionAttribute.cs
- SpStreamWrapper.cs
- WindowsClaimSet.cs
- ProjectionPruner.cs
- StatusStrip.cs
- CodeThrowExceptionStatement.cs
- EventMetadata.cs
- WebBaseEventKeyComparer.cs
- QueryConverter.cs
- TextWriterTraceListener.cs
- RedistVersionInfo.cs
- XamlVector3DCollectionSerializer.cs
- ListControlBoundActionList.cs
- TextWriter.cs
- StringExpressionSet.cs
- XmlTextWriter.cs
- Button.cs
- CaseStatementProjectedSlot.cs
- UriTemplateLiteralQueryValue.cs
- WebPartConnectionCollection.cs