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
- MessageQueuePermissionEntry.cs
- ErrorProvider.cs
- IODescriptionAttribute.cs
- WriteableBitmap.cs
- AutoGeneratedFieldProperties.cs
- XPathSelfQuery.cs
- PathFigureCollection.cs
- ProgressChangedEventArgs.cs
- XpsTokenContext.cs
- TileModeValidation.cs
- BaseValidator.cs
- VirtualizingPanel.cs
- SecurityDocument.cs
- VisualBasicSettingsHandler.cs
- ParentQuery.cs
- DocComment.cs
- BitVector32.cs
- SafeNativeMethods.cs
- TextRangeSerialization.cs
- SettingsSavedEventArgs.cs
- RegexParser.cs
- ObjectListDataBindEventArgs.cs
- PagePropertiesChangingEventArgs.cs
- ConnectionManagementElementCollection.cs
- Win32NamedPipes.cs
- SqlTriggerContext.cs
- AlphaSortedEnumConverter.cs
- SettingsBindableAttribute.cs
- StylusPointPropertyUnit.cs
- DynamicPropertyReader.cs
- OdbcError.cs
- AlignmentYValidation.cs
- hresults.cs
- DocumentEventArgs.cs
- ImageButton.cs
- ModuleElement.cs
- RoleManagerModule.cs
- StringUtil.cs
- GregorianCalendarHelper.cs
- ValidationHelper.cs
- Delegate.cs
- DeploymentExceptionMapper.cs
- Repeater.cs
- AuthorizationContext.cs
- SendMailErrorEventArgs.cs
- Base64Stream.cs
- ExpandCollapseIsCheckedConverter.cs
- ApplicationServicesHostFactory.cs
- WebBrowserSiteBase.cs
- safelinkcollection.cs
- WebRequest.cs
- ProgressPage.cs
- ADRoleFactoryConfiguration.cs
- BitmapImage.cs
- HMAC.cs
- MaxSessionCountExceededException.cs
- SizeChangedInfo.cs
- precedingsibling.cs
- BitmapCodecInfoInternal.cs
- Size3D.cs
- TextRunCache.cs
- EntityDataSourceWrapper.cs
- WebBrowserNavigatingEventHandler.cs
- DataColumnMappingCollection.cs
- WindowsStartMenu.cs
- WriteFileContext.cs
- EditingScopeUndoUnit.cs
- DoubleLinkListEnumerator.cs
- LogLogRecordHeader.cs
- CustomAttributeSerializer.cs
- Context.cs
- ImageIndexEditor.cs
- SettingsPropertyWrongTypeException.cs
- CompositeFontParser.cs
- MenuItemBindingCollection.cs
- _Win32.cs
- FormViewInsertedEventArgs.cs
- Interlocked.cs
- StreamInfo.cs
- SQLCharsStorage.cs
- WindowAutomationPeer.cs
- AdRotatorDesigner.cs
- TdsRecordBufferSetter.cs
- ImageCreator.cs
- ProfileBuildProvider.cs
- QuaternionAnimationUsingKeyFrames.cs
- SqlXml.cs
- ConfigurationException.cs
- OdbcConnectionHandle.cs
- HttpDictionary.cs
- PrintEvent.cs
- UriScheme.cs
- ItemMap.cs
- MarkupCompilePass1.cs
- ListenerSessionConnectionReader.cs
- ComponentConverter.cs
- ProtectedProviderSettings.cs
- ConfigurationManagerHelperFactory.cs
- CommandCollectionEditor.cs
- DurableDispatcherAddressingFault.cs