Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Routing / System / ServiceModel / Routing / ClientFactory.cs / 1305376 / ClientFactory.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.ServiceModel.Routing { using System; using System.Collections.Generic; using System.Runtime; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; using System.Transactions; static class ClientFactory { public static IRoutingClient Create(RoutingEndpointTrait endpointTrait, RoutingService service, bool impersonating) { Type contractType = endpointTrait.RouterContract; IRoutingClient client; if (contractType == typeof(ISimplexDatagramRouter)) { client = new SimplexDatagramClient(endpointTrait, service.RoutingConfig, impersonating); } else if (contractType == typeof(IRequestReplyRouter)) { client = new RequestReplyClient(endpointTrait, service.RoutingConfig, impersonating); } else if (contractType == typeof(ISimplexSessionRouter)) { client = new SimplexSessionClient(endpointTrait, service.RoutingConfig, impersonating); } else //if (contractType == typeof(IDuplexSessionRouter)) { Fx.Assert(contractType == typeof(IDuplexSessionRouter), "Only one contract type remaining."); client = new DuplexSessionClient(service, endpointTrait, impersonating); } return client; } abstract class RoutingClientBase: ClientBase , IRoutingClient where TChannel : class { bool openCompleted; object thisLock; Queue waiters; protected RoutingClientBase(RoutingEndpointTrait endpointTrait, RoutingConfiguration routingConfig, bool impersonating) : base(endpointTrait.Endpoint.Binding, endpointTrait.Endpoint.Address) { Initialize(endpointTrait, routingConfig, impersonating); } protected RoutingClientBase(RoutingEndpointTrait endpointTrait, RoutingConfiguration routingConfig, object callbackInstance, bool impersonating) : base(new InstanceContext(callbackInstance), endpointTrait.Endpoint.Binding, endpointTrait.Endpoint.Address) { Initialize(endpointTrait, routingConfig, impersonating); } public RoutingEndpointTrait Key { get; private set; } public event EventHandler Faulted; static void ConfigureImpersonation(ServiceEndpoint endpoint, bool impersonating) { // Used for both impersonation and ASP.NET Compatibilty Mode. Both currently require // everything to be synchronous. if (impersonating) { CustomBinding binding = endpoint.Binding as CustomBinding; if (binding == null) { binding = new CustomBinding(endpoint.Binding); } SynchronousSendBindingElement syncSend = binding.Elements.Find (); if (syncSend == null) { binding.Elements.Insert(0, new SynchronousSendBindingElement()); endpoint.Binding = binding; } } } static void ConfigureTransactionFlow(ServiceEndpoint endpoint) { CustomBinding binding = endpoint.Binding as CustomBinding; if (binding == null) { binding = new CustomBinding(endpoint.Binding); } TransactionFlowBindingElement transactionFlow = binding.Elements.Find (); if (transactionFlow != null) { transactionFlow.AllowWildcardAction = true; endpoint.Binding = binding; } } void Initialize(RoutingEndpointTrait endpointTrait, RoutingConfiguration routingConfig, bool impersonating) { this.thisLock = new object(); this.Key = endpointTrait; if (TD.RoutingServiceCreatingClientForEndpointIsEnabled()) { TD.RoutingServiceCreatingClientForEndpoint(this.Key.ToString()); } ServiceEndpoint clientEndpoint = endpointTrait.Endpoint; ServiceEndpoint endpoint = this.Endpoint; KeyedByTypeCollection behaviors = endpoint.Behaviors; endpoint.ListenUri = clientEndpoint.ListenUri; endpoint.ListenUriMode = clientEndpoint.ListenUriMode; endpoint.Name = clientEndpoint.Name; foreach (IEndpointBehavior behavior in clientEndpoint.Behaviors) { // Remove if present, ok to call if not there (will simply return false) behaviors.Remove(behavior.GetType()); behaviors.Add(behavior); } // If the configuration doesn't explicitly add MustUnderstandBehavior (to override us) // add it here, with mustunderstand = false. if (behaviors.Find () == null) { behaviors.Add(new MustUnderstandBehavior(false)); } // If the configuration doesn't explicitly turn off marshaling we add it here. if (routingConfig.SoapProcessingEnabled && behaviors.Find () == null) { behaviors.Add(new SoapProcessingBehavior()); } ConfigureTransactionFlow(endpoint); ConfigureImpersonation(endpoint, impersonating); } protected override TChannel CreateChannel() { TChannel channel = base.CreateChannel(); ((ICommunicationObject)channel).Faulted += this.InnerChannelFaulted; return channel; } public IAsyncResult BeginOperation(Message message, Transaction transaction, AsyncCallback callback, object state) { return new OperationAsyncResult(this, message, transaction, callback, state); } public Message EndOperation(IAsyncResult result) { return OperationAsyncResult.End(result); } protected abstract IAsyncResult OnBeginOperation(Message message, AsyncCallback callback, object state); protected abstract Message OnEndOperation(IAsyncResult asyncResult); void InnerChannelFaulted(object sender, EventArgs args) { EventHandler handlers = this.Faulted; if (handlers != null) { handlers(this, args); } } class OperationAsyncResult : AsyncResult { static AsyncCompletion openComplete = OpenComplete; static AsyncCompletion operationComplete = OperationComplete; static Action
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TemplatedMailWebEventProvider.cs
- FeatureSupport.cs
- BitmapEffect.cs
- TaskFileService.cs
- ResourcePart.cs
- TextPenaltyModule.cs
- TrackingConditionCollection.cs
- GridSplitterAutomationPeer.cs
- LineBreak.cs
- TrackingExtract.cs
- ProcessProtocolHandler.cs
- TypeSource.cs
- VirtualizingStackPanel.cs
- MimeBasePart.cs
- MailFileEditor.cs
- IISMapPath.cs
- HttpConfigurationContext.cs
- Properties.cs
- PersonalizationStateInfoCollection.cs
- InputReferenceExpression.cs
- DataGridViewRowsRemovedEventArgs.cs
- ToggleButton.cs
- CodeTypeParameterCollection.cs
- SemaphoreSecurity.cs
- PersonalizationProviderHelper.cs
- TemplatePropertyEntry.cs
- NumberSubstitution.cs
- ProtocolsConfigurationEntry.cs
- WebProxyScriptElement.cs
- DataGridrowEditEndingEventArgs.cs
- Simplifier.cs
- TextSerializer.cs
- XmlChoiceIdentifierAttribute.cs
- DoneReceivingAsyncResult.cs
- ComponentConverter.cs
- SchemaMapping.cs
- OptimisticConcurrencyException.cs
- SmiTypedGetterSetter.cs
- SafeNativeMemoryHandle.cs
- StringAnimationUsingKeyFrames.cs
- Clipboard.cs
- SocketPermission.cs
- SignatureToken.cs
- ButtonFlatAdapter.cs
- CollectionDataContractAttribute.cs
- WebFormDesignerActionService.cs
- PropertyEmitter.cs
- TemplateXamlTreeBuilder.cs
- ObjectRef.cs
- SqlTopReducer.cs
- AppDomainAttributes.cs
- File.cs
- NameTable.cs
- EpmCustomContentWriterNodeData.cs
- NoClickablePointException.cs
- Metadata.cs
- RadialGradientBrush.cs
- SectionInformation.cs
- EnumDataContract.cs
- SharedPerformanceCounter.cs
- SessionState.cs
- Range.cs
- EntitySetBase.cs
- Point4D.cs
- MessageDesigner.cs
- AutomationProperties.cs
- EncryptedData.cs
- FormatConvertedBitmap.cs
- ReferencedType.cs
- CultureInfoConverter.cs
- SQLGuidStorage.cs
- DrawingContext.cs
- WebPartDesigner.cs
- DataGridView.cs
- WebControl.cs
- GlobalItem.cs
- StringDictionary.cs
- MDIClient.cs
- ItemsPanelTemplate.cs
- InstanceKeyNotReadyException.cs
- MergeLocalizationDirectives.cs
- PathFigureCollection.cs
- _emptywebproxy.cs
- AnimationException.cs
- IDQuery.cs
- OdbcRowUpdatingEvent.cs
- HitTestDrawingContextWalker.cs
- CodeAttachEventStatement.cs
- XamlPoint3DCollectionSerializer.cs
- InfoCardTraceRecord.cs
- ClientSettingsStore.cs
- ToolboxItem.cs
- ImageCodecInfo.cs
- PropertyDescriptorComparer.cs
- FlowDocumentFormatter.cs
- RightsManagementEncryptedStream.cs
- FormViewModeEventArgs.cs
- UIPropertyMetadata.cs
- ThumbAutomationPeer.cs
- CqlQuery.cs