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
- DataGridRelationshipRow.cs
- SmiTypedGetterSetter.cs
- ClientSideProviderDescription.cs
- MetadataCacheItem.cs
- ExpressionBindingCollection.cs
- PnrpPermission.cs
- RowType.cs
- PagesSection.cs
- PeerResolverMode.cs
- FilterableAttribute.cs
- SweepDirectionValidation.cs
- ToolStripDropDownItem.cs
- InvalidProgramException.cs
- GuidConverter.cs
- DeploymentSection.cs
- MessageBox.cs
- XmlSchemaAttribute.cs
- Stack.cs
- URLBuilder.cs
- StyleSheetRefUrlEditor.cs
- IBuiltInEvidence.cs
- ChunkedMemoryStream.cs
- ColorKeyFrameCollection.cs
- _DomainName.cs
- HtmlContainerControl.cs
- ResourceManager.cs
- StackBuilderSink.cs
- PropertyGridEditorPart.cs
- BitmapInitialize.cs
- SimpleHandlerFactory.cs
- CompoundFileIOPermission.cs
- SynchronizationValidator.cs
- Vector3D.cs
- OleDbErrorCollection.cs
- ApplicationDirectory.cs
- DBBindings.cs
- DrawingBrush.cs
- SecUtil.cs
- DataGridViewHeaderCell.cs
- RegexFCD.cs
- BitArray.cs
- ApplicationHost.cs
- SrgsToken.cs
- LinkDescriptor.cs
- ListViewCommandEventArgs.cs
- SqlCacheDependencySection.cs
- TextEndOfParagraph.cs
- RadialGradientBrush.cs
- Queue.cs
- MetabaseSettings.cs
- RelationshipManager.cs
- RSAPKCS1SignatureFormatter.cs
- DataObjectSettingDataEventArgs.cs
- ProtectedConfiguration.cs
- ChangeNode.cs
- MulticastDelegate.cs
- XsltContext.cs
- MeshGeometry3D.cs
- BaseCodePageEncoding.cs
- StringUtil.cs
- errorpatternmatcher.cs
- RelationshipWrapper.cs
- LicenseContext.cs
- WorkflowInstance.cs
- BooleanFacetDescriptionElement.cs
- BufferAllocator.cs
- ScriptResourceInfo.cs
- AmbiguousMatchException.cs
- SchemaCollectionPreprocessor.cs
- TreeNodeConverter.cs
- FixedTextContainer.cs
- MdiWindowListItemConverter.cs
- ListViewSelectEventArgs.cs
- HttpClientCertificate.cs
- TemplatedMailWebEventProvider.cs
- EventMappingSettingsCollection.cs
- IUnknownConstantAttribute.cs
- DataGridToolTip.cs
- CodeValidator.cs
- TransactionsSectionGroup.cs
- LinqDataSourceStatusEventArgs.cs
- GenericIdentity.cs
- FormViewModeEventArgs.cs
- XmlLoader.cs
- StickyNoteHelper.cs
- CapabilitiesAssignment.cs
- HMACMD5.cs
- FunctionNode.cs
- UrlPath.cs
- LocalizableAttribute.cs
- BinHexDecoder.cs
- DataKeyCollection.cs
- EdmComplexPropertyAttribute.cs
- SqlEnums.cs
- ResizeGrip.cs
- Module.cs
- StoreContentChangedEventArgs.cs
- IPPacketInformation.cs
- StylusButton.cs
- HtmlMeta.cs