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
- ExpressionTextBox.xaml.cs
- FtpWebResponse.cs
- Char.cs
- TextDecorationUnitValidation.cs
- BitmapEncoder.cs
- EntityReference.cs
- xmlglyphRunInfo.cs
- FlowDocumentPage.cs
- ClientBase.cs
- ThreadExceptionEvent.cs
- StandardCommands.cs
- HttpListenerPrefixCollection.cs
- DataGridPageChangedEventArgs.cs
- QuerySettings.cs
- RewritingPass.cs
- XmlDomTextWriter.cs
- DTCTransactionManager.cs
- ViewDesigner.cs
- FrameSecurityDescriptor.cs
- DBBindings.cs
- AssemblyBuilderData.cs
- ChildDocumentBlock.cs
- OledbConnectionStringbuilder.cs
- WmlPhoneCallAdapter.cs
- ToolStripSettings.cs
- SiteMapPath.cs
- ImageMap.cs
- validation.cs
- TypeUtils.cs
- ExceptionUtil.cs
- DataGridViewCellValidatingEventArgs.cs
- NullableDecimalSumAggregationOperator.cs
- RawStylusInputCustomDataList.cs
- NameSpaceExtractor.cs
- XmlObjectSerializerWriteContext.cs
- MessageContractExporter.cs
- AssertFilter.cs
- ManifestSignatureInformation.cs
- DispatcherOperation.cs
- PriorityQueue.cs
- ApplicationManager.cs
- XmlEnumAttribute.cs
- DBSchemaRow.cs
- StorageSetMapping.cs
- ProcessRequestArgs.cs
- WindowPatternIdentifiers.cs
- SelectionItemProviderWrapper.cs
- SByteConverter.cs
- StickyNoteAnnotations.cs
- WindowsMenu.cs
- TreeViewAutomationPeer.cs
- PointLight.cs
- DoubleCollection.cs
- PostBackOptions.cs
- AppDomainManager.cs
- StringReader.cs
- DivideByZeroException.cs
- UInt64.cs
- Typography.cs
- Visual3D.cs
- RuleSettings.cs
- BinaryCommonClasses.cs
- MultiPartWriter.cs
- Hex.cs
- sqlpipe.cs
- PartialCachingAttribute.cs
- LabelEditEvent.cs
- XmlSchemaGroupRef.cs
- Queue.cs
- BitVector32.cs
- MembershipSection.cs
- InstanceHandleReference.cs
- BinaryQueryOperator.cs
- ParameterToken.cs
- EntryPointNotFoundException.cs
- DataGridView.cs
- FastEncoder.cs
- ReferentialConstraint.cs
- KeyValueSerializer.cs
- EntityKey.cs
- InputBinder.cs
- RemotingAttributes.cs
- COMException.cs
- EntityContainerRelationshipSet.cs
- CuspData.cs
- SimpleTypeResolver.cs
- EmptyQuery.cs
- WpfXamlType.cs
- TextViewBase.cs
- TaskFileService.cs
- PathFigureCollection.cs
- ViewPort3D.cs
- SystemNetworkInterface.cs
- ValueHandle.cs
- HostUtils.cs
- SqlErrorCollection.cs
- StateBag.cs
- GenericsInstances.cs
- TimerEventSubscription.cs
- TraceLevelStore.cs