Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Discovery / System / ServiceModel / Discovery / AnnouncementClient.cs / 1305376 / AnnouncementClient.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.ServiceModel.Discovery { using System; using System.ComponentModel; using System.Runtime; using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Discovery.Configuration; using System.Xml; using SR2 = System.ServiceModel.Discovery.SR; [Fx.Tag.XamlVisible(false)] public sealed class AnnouncementClient : ICommunicationObject, IDisposable { IAnnouncementInnerClient innerClient; public AnnouncementClient() : this("*") { } public AnnouncementClient(string endpointConfigurationName) { if (endpointConfigurationName == null) { throw FxTrace.Exception.ArgumentNull("endpointConfigurationName"); } AnnouncementEndpoint announcementEndpoint = ConfigurationUtility.LookupEndpointFromClientSection( endpointConfigurationName); Initialize(announcementEndpoint); } public AnnouncementClient(AnnouncementEndpoint announcementEndpoint) { if (announcementEndpoint == null) { throw FxTrace.Exception.ArgumentNull("announcementEndpoint"); } Initialize(announcementEndpoint); } public event EventHandler AnnounceOnlineCompleted { add { if (this.InternalAnnounceOnlineCompleted == null) { this.innerClient.HelloOperationCompleted += OnInnerClientHelloCompleted; } this.InternalAnnounceOnlineCompleted += value; } remove { this.InternalAnnounceOnlineCompleted -= value; if (this.InternalAnnounceOnlineCompleted == null) { this.innerClient.HelloOperationCompleted -= OnInnerClientHelloCompleted; } } } public event EventHandler AnnounceOfflineCompleted { add { if (this.InternalAnnounceOfflineCompleted == null) { this.innerClient.ByeOperationCompleted += OnInnerClientByeCompleted; } this.InternalAnnounceOfflineCompleted += value; } remove { this.InternalAnnounceOfflineCompleted -= value; if (this.InternalAnnounceOfflineCompleted == null) { this.innerClient.ByeOperationCompleted -= OnInnerClientByeCompleted; } } } event EventHandler InternalAnnounceOnlineCompleted; event EventHandler InternalAnnounceOfflineCompleted; event EventHandler ICommunicationObject.Closed { add { if (this.InternalClosed == null) { this.InnerCommunicationObject.Closed += OnInnerCommunicationObjectClosed; } this.InternalClosed += value; } remove { this.InternalClosed -= value; if (this.InternalClosed == null) { this.InnerCommunicationObject.Closed -= OnInnerCommunicationObjectClosed; } } } event EventHandler ICommunicationObject.Closing { add { if (this.InternalClosing == null) { this.InnerCommunicationObject.Closing += OnInnerCommunicationObjectClosing; } this.InternalClosing += value; } remove { this.InternalClosing -= value; if (this.InternalClosing == null) { this.InnerCommunicationObject.Closing -= OnInnerCommunicationObjectClosing; } } } event EventHandler ICommunicationObject.Faulted { add { if (this.InternalFaulted == null) { this.InnerCommunicationObject.Faulted += OnInnerCommunicationObjectFaulted; } this.InternalFaulted += value; } remove { this.InternalFaulted -= value; if (this.InternalFaulted == null) { this.InnerCommunicationObject.Faulted -= OnInnerCommunicationObjectFaulted; } } } event EventHandler ICommunicationObject.Opened { add { if (this.InternalOpened == null) { this.InnerCommunicationObject.Opened += OnInnerCommunicationObjectOpened; } this.InternalOpened += value; } remove { this.InternalOpened -= value; if (this.InternalOpened == null) { this.InnerCommunicationObject.Opened -= OnInnerCommunicationObjectOpened; } } } event EventHandler ICommunicationObject.Opening { add { if (this.InternalOpening == null) { this.InnerCommunicationObject.Opening += OnInnerCommunicationObjectOpening; } this.InternalOpening += value; } remove { this.InternalOpening -= value; if (this.InternalOpening == null) { this.InnerCommunicationObject.Opening -= OnInnerCommunicationObjectOpening; } } } event EventHandler InternalClosed; event EventHandler InternalClosing; event EventHandler InternalFaulted; event EventHandler InternalOpened; event EventHandler InternalOpening; public DiscoveryMessageSequenceGenerator MessageSequenceGenerator { get { return this.innerClient.DiscoveryMessageSequenceGenerator; } set { if (value == null) { throw FxTrace.Exception.ArgumentNull("value"); } if (((ICommunicationObject)this).State != CommunicationState.Created) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.DiscoverySetMessageSequenceInvalidState)); } this.innerClient.DiscoveryMessageSequenceGenerator = value; } } public ChannelFactory ChannelFactory { get { return InnerClient.ChannelFactory; } } public ClientCredentials ClientCredentials { get { return InnerClient.ClientCredentials; } } public ServiceEndpoint Endpoint { get { return InnerClient.Endpoint; } } public IClientChannel InnerChannel { get { return InnerClient.InnerChannel; } } CommunicationState ICommunicationObject.State { get { return InnerCommunicationObject.State; } } IAnnouncementInnerClient InnerClient { get { return this.innerClient; } } ICommunicationObject InnerCommunicationObject { get { return InnerClient.InnerCommunicationObject; } } [Fx.Tag.Blocking(CancelMethod = "Abort", CancelDeclaringType = typeof(ICommunicationObject))] [Fx.Tag.InheritThrows(From = "Open", FromDeclaringType = typeof(ICommunicationObject))] public void Open() { ((ICommunicationObject)this).Open(); } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] public void AnnounceOnlineAsync(EndpointDiscoveryMetadata discoveryMetadata) { AnnounceOnlineAsync(discoveryMetadata, null); } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] public void AnnounceOnlineAsync(EndpointDiscoveryMetadata discoveryMetadata, object userState) { if (discoveryMetadata == null) { throw FxTrace.Exception.ArgumentNull("discoveryMetadata"); } using (new AnnouncementOperationContextScope(InnerChannel)) { InnerClient.HelloOperationAsync(discoveryMetadata, userState); } } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] public void AnnounceOfflineAsync(EndpointDiscoveryMetadata discoveryMetadata) { AnnounceOfflineAsync(discoveryMetadata, null); } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] public void AnnounceOfflineAsync(EndpointDiscoveryMetadata discoveryMetadata, object userState) { if (discoveryMetadata == null) { throw FxTrace.Exception.ArgumentNull("discoveryMetadata"); } using (new AnnouncementOperationContextScope(InnerChannel)) { InnerClient.ByeOperationAsync(discoveryMetadata, userState); } } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] [Fx.Tag.Blocking(CancelMethod = "Abort")] public void AnnounceOnline(EndpointDiscoveryMetadata discoveryMetadata) { if (discoveryMetadata == null) { throw FxTrace.Exception.ArgumentNull("discoveryMetadata"); } using (new AnnouncementOperationContextScope(InnerChannel)) { this.InnerClient.HelloOperation(discoveryMetadata); } } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] [Fx.Tag.Blocking(CancelMethod = "Abort")] public void AnnounceOffline(EndpointDiscoveryMetadata discoveryMetadata) { if (discoveryMetadata == null) { throw FxTrace.Exception.ArgumentNull("discoveryMetadata"); } using (new AnnouncementOperationContextScope(InnerChannel)) { this.InnerClient.ByeOperation(discoveryMetadata); } } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] public IAsyncResult BeginAnnounceOnline(EndpointDiscoveryMetadata discoveryMetadata, AsyncCallback callback, object state) { if (discoveryMetadata == null) { throw FxTrace.Exception.ArgumentNull("discoveryMetadata"); } using (new AnnouncementOperationContextScope(InnerChannel)) { return InnerClient.BeginHelloOperation(discoveryMetadata, callback, state); } } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] public void EndAnnounceOnline(IAsyncResult result) { InnerClient.EndHelloOperation(result); } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] public IAsyncResult BeginAnnounceOffline(EndpointDiscoveryMetadata discoveryMetadata, AsyncCallback callback, object state) { if (discoveryMetadata == null) { throw FxTrace.Exception.ArgumentNull("discoveryMetadata"); } using (new AnnouncementOperationContextScope(InnerChannel)) { return InnerClient.BeginByeOperation(discoveryMetadata, callback, state); } } [Fx.Tag.Throws(typeof(CommunicationException), "Inherits from Channel exception contract")] [Fx.Tag.Throws(typeof(TimeoutException), "Inherits from Channel exception contract")] public void EndAnnounceOffline(IAsyncResult result) { InnerClient.EndByeOperation(result); } [Fx.Tag.Blocking(CancelMethod = "Abort", CancelDeclaringType = typeof(ICommunicationObject))] [Fx.Tag.InheritThrows(From = "Close", FromDeclaringType = typeof(ICommunicationObject))] public void Close() { ((ICommunicationObject)this).Close(); } [Fx.Tag.Blocking(CancelMethod = "Abort", CancelDeclaringType = typeof(ICommunicationObject))] [Fx.Tag.InheritThrows(From = "Open", FromDeclaringType = typeof(ICommunicationObject))] void ICommunicationObject.Open() { InnerCommunicationObject.Open(); } [Fx.Tag.Blocking(CancelMethod = "Abort", CancelDeclaringType = typeof(ICommunicationObject))] [Fx.Tag.InheritThrows(From = "Open", FromDeclaringType = typeof(ICommunicationObject))] void ICommunicationObject.Open(TimeSpan timeout) { InnerCommunicationObject.Open(timeout); } [Fx.Tag.InheritThrows(From = "BeginOpen", FromDeclaringType = typeof(ICommunicationObject))] IAsyncResult ICommunicationObject.BeginOpen(AsyncCallback callback, object state) { return InnerCommunicationObject.BeginOpen(callback, state); } [Fx.Tag.InheritThrows(From = "BeginOpen", FromDeclaringType = typeof(ICommunicationObject))] IAsyncResult ICommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, object state) { return InnerCommunicationObject.BeginOpen(timeout, callback, state); } [Fx.Tag.InheritThrows(From = "EndOpen", FromDeclaringType = typeof(ICommunicationObject))] void ICommunicationObject.EndOpen(IAsyncResult result) { InnerCommunicationObject.EndOpen(result); } [Fx.Tag.Blocking(CancelMethod = "Abort", CancelDeclaringType = typeof(ICommunicationObject))] [Fx.Tag.InheritThrows(From = "Close", FromDeclaringType = typeof(ICommunicationObject))] void ICommunicationObject.Close() { InnerCommunicationObject.Close(); } [Fx.Tag.Blocking(CancelMethod = "Abort", CancelDeclaringType = typeof(ICommunicationObject))] [Fx.Tag.InheritThrows(From = "Close", FromDeclaringType = typeof(ICommunicationObject))] void ICommunicationObject.Close(TimeSpan timeout) { InnerCommunicationObject.Close(timeout); } [Fx.Tag.InheritThrows(From = "BeginClose", FromDeclaringType = typeof(ICommunicationObject))] IAsyncResult ICommunicationObject.BeginClose(AsyncCallback callback, object state) { return InnerCommunicationObject.BeginClose(callback, state); } [Fx.Tag.InheritThrows(From = "BeginClose", FromDeclaringType = typeof(ICommunicationObject))] IAsyncResult ICommunicationObject.BeginClose(TimeSpan timeout, AsyncCallback callback, object state) { return InnerCommunicationObject.BeginClose(timeout, callback, state); } [Fx.Tag.InheritThrows(From = "EndClose", FromDeclaringType = typeof(ICommunicationObject))] void ICommunicationObject.EndClose(IAsyncResult result) { InnerCommunicationObject.EndClose(result); } [Fx.Tag.InheritThrows(From = "Abort", FromDeclaringType = typeof(ICommunicationObject))] void ICommunicationObject.Abort() { InnerCommunicationObject.Abort(); } void IDisposable.Dispose() { this.Close(); } void Initialize(AnnouncementEndpoint announcementEndpoint) { this.innerClient = announcementEndpoint.DiscoveryVersion.Implementation.CreateAnnouncementInnerClient(announcementEndpoint); } void RaiseEvent(EventHandler handler, EventArgs e) { if (handler != null) { handler(this, e); } } void OnInnerCommunicationObjectClosed(object sender, EventArgs e) { RaiseEvent(this.InternalClosed, e); } void OnInnerCommunicationObjectClosing(object sender, EventArgs e) { RaiseEvent(this.InternalClosing, e); } void OnInnerCommunicationObjectFaulted(object sender, EventArgs e) { RaiseEvent(this.InternalFaulted, e); } void OnInnerCommunicationObjectOpened(object sender, EventArgs e) { RaiseEvent(this.InternalOpened, e); } void OnInnerCommunicationObjectOpening(object sender, EventArgs e) { RaiseEvent(this.InternalOpening, e); } void OnInnerClientHelloCompleted(object sender, AsyncCompletedEventArgs e) { EventHandler handler = this.InternalAnnounceOnlineCompleted; if (handler != null) { handler(this, e); } } void OnInnerClientByeCompleted(object sender, AsyncCompletedEventArgs e) { EventHandler handler = this.InternalAnnounceOfflineCompleted; if (handler != null) { handler(this, e); } } sealed class AnnouncementOperationContextScope : IDisposable { OperationContextScope operationContextScope; UniqueId originalMessageId = null; public AnnouncementOperationContextScope(IClientChannel clientChannel) { if (DiscoveryUtility.IsCompatible(OperationContext.Current, clientChannel)) { // reuse the same context this.originalMessageId = OperationContext.Current.OutgoingMessageHeaders.MessageId; } else { // create new context this.operationContextScope = new OperationContextScope(clientChannel); } if (this.originalMessageId == null) { // this is either a new context or an existing one with no message id. OperationContext.Current.OutgoingMessageHeaders.MessageId = new UniqueId(); } } public void Dispose() { if (this.operationContextScope != null) { this.operationContextScope.Dispose(); } else { OperationContext.Current.OutgoingMessageHeaders.MessageId = this.originalMessageId; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EncodingDataItem.cs
- FixedLineResult.cs
- HiddenFieldPageStatePersister.cs
- XmlDictionary.cs
- FieldBuilder.cs
- WindowsScrollBarBits.cs
- SqlUserDefinedTypeAttribute.cs
- odbcmetadatacolumnnames.cs
- TerminatorSinks.cs
- ParseNumbers.cs
- MenuAdapter.cs
- CompilationUnit.cs
- StickyNoteContentControl.cs
- GeneralTransform3DTo2DTo3D.cs
- TemplateBindingExtension.cs
- X509Utils.cs
- UIElement3D.cs
- TypeExtensionConverter.cs
- BamlLocalizer.cs
- MultiAsyncResult.cs
- TypedDatasetGenerator.cs
- CharAnimationBase.cs
- CompensationToken.cs
- SafeSerializationManager.cs
- MemoryRecordBuffer.cs
- IImplicitResourceProvider.cs
- FileVersionInfo.cs
- ExpressionNode.cs
- Thumb.cs
- XsdDateTime.cs
- TreeNode.cs
- RequestCacheEntry.cs
- RequestCacheEntry.cs
- _RequestCacheProtocol.cs
- XmlSchemaInferenceException.cs
- SessionEndedEventArgs.cs
- NumberFormatter.cs
- GridViewItemAutomationPeer.cs
- SamlAssertionKeyIdentifierClause.cs
- ObjectTokenCategory.cs
- UnsafeNativeMethodsCLR.cs
- ColumnBinding.cs
- CodeEntryPointMethod.cs
- GroupAggregateExpr.cs
- PagerSettings.cs
- StyleSheetDesigner.cs
- WindowsGraphicsWrapper.cs
- RegionIterator.cs
- WmlFormAdapter.cs
- DependencyPropertyDescriptor.cs
- ColorConvertedBitmapExtension.cs
- XmlSchemaDocumentation.cs
- LogicalExpr.cs
- ProcessActivityTreeOptions.cs
- OneOfElement.cs
- XmlEncoding.cs
- HtmlProps.cs
- ListBoxChrome.cs
- GregorianCalendarHelper.cs
- MenuCommandsChangedEventArgs.cs
- FileVersionInfo.cs
- XmlQualifiedNameTest.cs
- SQLString.cs
- ImageMapEventArgs.cs
- DSASignatureDeformatter.cs
- BuildProviderAppliesToAttribute.cs
- TextElementEnumerator.cs
- ArrangedElement.cs
- BuildProviderCollection.cs
- ContextMenuStrip.cs
- FontUnitConverter.cs
- ProtocolElementCollection.cs
- MetadataItemEmitter.cs
- Vector3DIndependentAnimationStorage.cs
- QuaternionRotation3D.cs
- HttpConfigurationSystem.cs
- ParallelEnumerable.cs
- FixedBufferAttribute.cs
- AQNBuilder.cs
- MatrixCamera.cs
- VisualTreeHelper.cs
- ListCardsInFileRequest.cs
- Compilation.cs
- MultiTargetingUtil.cs
- TextPointerBase.cs
- TypeHelpers.cs
- XmlSchemaSimpleTypeRestriction.cs
- ResolveDuplexCD1AsyncResult.cs
- SQLUtility.cs
- ContextMenuStrip.cs
- LoginAutoFormat.cs
- StreamGeometryContext.cs
- XmlReader.cs
- CoTaskMemUnicodeSafeHandle.cs
- DragAssistanceManager.cs
- EntityCollection.cs
- LinkLabelLinkClickedEvent.cs
- BaseConfigurationRecord.cs
- Win32Exception.cs
- DataView.cs