Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / ComIntegration / TypedServiceChannelBuilder.cs / 1 / TypedServiceChannelBuilder.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #pragma warning disable 1634, 1691 namespace System.ServiceModel.ComIntegration { using System; using System.ServiceModel.Description; using System.Reflection; using System.Collections.Generic; using System.Threading; using System.ServiceModel; using System.ServiceModel.Channels; using System.Runtime.Remoting.Proxies; using System.Runtime.Remoting; using System.Runtime.InteropServices; using System.Diagnostics; using System.ServiceModel.Diagnostics; internal class TypedServiceChannelBuilder : IProxyCreator, IProvideChannelBuilderSettings, ICreateServiceChannel { ServiceChannelFactory serviceChannelFactory = null; Type contractType = null; RealProxy serviceProxy = null; ServiceEndpoint serviceEndpoint = null; KeyedByTypeCollectionbehaviors = new KeyedByTypeCollection (); Binding binding = null; string configurationName = null ; string address = null; EndpointIdentity identity = null; void IDisposable.Dispose () { if (serviceProxy != null) { IChannel channel = serviceProxy.GetTransparentProxy () as IChannel; if (channel == null) { DiagnosticUtility.DebugAssert("serviceProxy MUST support IChannel"); #pragma warning suppress 56519 // throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } channel.Close (); } } //Suppressing PreSharp warning that property get methods should not throw #pragma warning disable 6503 ServiceChannelFactory IProvideChannelBuilderSettings.ServiceChannelFactoryReadWrite { get { if (serviceProxy != null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError (new COMException (SR.GetString (SR.TooLate), HR.RPC_E_TOO_LATE)); return serviceChannelFactory; } } #pragma warning restore 6503 ServiceChannelFactory IProvideChannelBuilderSettings.ServiceChannelFactoryReadOnly { get { return serviceChannelFactory; } } //Suppressing PreSharp warning that property get methods should not throw #pragma warning disable 6503 KeyedByTypeCollection IProvideChannelBuilderSettings.Behaviors { get { if (serviceProxy != null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError (new COMException (SR.GetString (SR.TooLate), HR.RPC_E_TOO_LATE)); return behaviors; } } #pragma warning restore 6503 ServiceChannel IProvideChannelBuilderSettings.ServiceChannel { get { return null; } } RealProxy ICreateServiceChannel.CreateChannel () { if (serviceProxy == null) { lock (this) { if (serviceProxy == null) { try { if (serviceChannelFactory == null) { FaultInserviceChannelFactory(); } if (serviceChannelFactory == null) { DiagnosticUtility.DebugAssert("ServiceChannelFactory cannot be null at this point"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } serviceChannelFactory.Open (); if (contractType == null) { DiagnosticUtility.DebugAssert("contractType cannot be null"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } if (serviceEndpoint == null) { DiagnosticUtility.DebugAssert("serviceEndpoint cannot be null"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } object transparentProxy = serviceChannelFactory.CreateChannel (contractType, new EndpointAddress(serviceEndpoint.Address.Uri, serviceEndpoint.Address.Identity, serviceEndpoint.Address.Headers), serviceEndpoint.Address.Uri); ComPlusChannelCreatedTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationChannelCreated, SR.TraceCodeComIntegrationChannelCreated, serviceEndpoint.Address.Uri, contractType); RealProxy localProxy = RemotingServices.GetRealProxy (transparentProxy); Thread.MemoryBarrier(); serviceProxy = localProxy; if (serviceProxy == null) { DiagnosticUtility.DebugAssert("serviceProxy MUST derive from RealProxy"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } } finally { if ((serviceProxy == null) && (serviceChannelFactory != null)) serviceChannelFactory.Close (); } } } } return serviceProxy; } private ServiceEndpoint CreateServiceEndpoint() { TypeLoader loader = new TypeLoader(); ContractDescription contractDescription = loader.LoadContractDescription(contractType); ServiceEndpoint endpoint = new ServiceEndpoint(contractDescription); if (address != null) endpoint.Address = new EndpointAddress(new Uri(address), identity); if (binding != null) endpoint.Binding = binding; if (configurationName != null) { ConfigLoader configLoader = new ConfigLoader(); configLoader.LoadChannelBehaviors(endpoint, configurationName); } ComPlusTypedChannelBuilderTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationTypedChannelBuilderLoaded, SR.TraceCodeComIntegrationTypedChannelBuilderLoaded, contractType, binding); return endpoint; } private ServiceChannelFactory CreateServiceChannelFactory () { ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(serviceEndpoint) as ServiceChannelFactory; if (serviceChannelFactory == null) { DiagnosticUtility.DebugAssert("We should get a ServiceChannelFactory back"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } return serviceChannelFactory; } void FaultInserviceChannelFactory () { if (contractType == null) { DiagnosticUtility.DebugAssert("contractType should not be null"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } if (serviceEndpoint == null) { serviceEndpoint = CreateServiceEndpoint(); } foreach (IEndpointBehavior behavior in behaviors) serviceEndpoint.Behaviors.Add(behavior); serviceChannelFactory = CreateServiceChannelFactory (); } internal void ResolveTypeIfPossible (Dictionary propertyTable ) { string typeIID; propertyTable.TryGetValue (MonikerHelper.MonikerAttribute.Contract, out typeIID); Guid iid; if (!string.IsNullOrEmpty(typeIID)) { try { dispatchEnabled = true; iid = new Guid (typeIID); TypeCacheManager.Provider.FindOrCreateType (iid, out contractType, true, false); serviceEndpoint = CreateServiceEndpoint(); } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) throw; throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException (SR.GetString(SR.TypeLoadForContractTypeIIDFailedWith, typeIID, e.Message))); } } } internal TypedServiceChannelBuilder (Dictionary propertyTable ) { string bindingType = null; string bindingConfigName = null; string spnIdentity = null; string upnIdentity = null; string dnsIdentity = null; propertyTable.TryGetValue (MonikerHelper.MonikerAttribute.Address, out address); propertyTable.TryGetValue (MonikerHelper.MonikerAttribute.Binding, out bindingType); propertyTable.TryGetValue (MonikerHelper.MonikerAttribute.BindingConfiguration, out bindingConfigName); propertyTable.TryGetValue (MonikerHelper.MonikerAttribute.SpnIdentity, out spnIdentity); propertyTable.TryGetValue (MonikerHelper.MonikerAttribute.UpnIdentity, out upnIdentity); propertyTable.TryGetValue (MonikerHelper.MonikerAttribute.DnsIdentity, out dnsIdentity); if (!string.IsNullOrEmpty(bindingType)) { try { binding = ConfigLoader.LookupBinding (bindingType, bindingConfigName); } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) throw; throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException (SR.GetString(SR.BindingLoadFromConfigFailedWith, bindingType, e.Message))); } if (binding == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException (SR.GetString(SR.BindingNotFoundInConfig, bindingType, bindingConfigName))); } if (binding == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.BindingNotSpecified))); if (string.IsNullOrEmpty(address)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.AddressNotSpecified))); if (!string.IsNullOrEmpty(spnIdentity )) { if ((!string.IsNullOrEmpty(upnIdentity))||(!string.IsNullOrEmpty(dnsIdentity))) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError (new MonikerSyntaxException (SR.GetString (SR.MonikerIncorrectServerIdentity))); identity = EndpointIdentity.CreateSpnIdentity(spnIdentity); } else if (!string.IsNullOrEmpty(upnIdentity)) { if ((!string.IsNullOrEmpty(spnIdentity))||(!string.IsNullOrEmpty(dnsIdentity))) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError (new MonikerSyntaxException (SR.GetString (SR.MonikerIncorrectServerIdentity))); identity = EndpointIdentity.CreateUpnIdentity(upnIdentity); } else if (!string.IsNullOrEmpty(dnsIdentity)) { if ((!string.IsNullOrEmpty(spnIdentity))||(!string.IsNullOrEmpty(upnIdentity))) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError (new MonikerSyntaxException (SR.GetString (SR.MonikerIncorrectServerIdentity))); identity = EndpointIdentity.CreateDnsIdentity(dnsIdentity); } else identity = null; ResolveTypeIfPossible (propertyTable); } bool dispatchEnabled = false; private bool CheckDispatch (ref Guid riid) { if ((dispatchEnabled) && (riid == InterfaceID.idIDispatch)) return true; else return false; } ComProxy IProxyCreator.CreateProxy (IntPtr outer, ref Guid riid) { if (outer == IntPtr.Zero) { DiagnosticUtility.DebugAssert("OuterProxy cannot be null"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } // No contract Fault on in if (contractType == null) TypeCacheManager.Provider.FindOrCreateType (riid, out contractType, true, false); if ((contractType.GUID != riid) && !(CheckDispatch (ref riid))) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(SR.GetString(SR.NoInterface, riid))); Type proxiedType = EmitterCache.TypeEmitter.FindOrCreateType (contractType); ComProxy comProxy = null; TearOffProxy tearoffProxy = null; try { tearoffProxy = new TearOffProxy (this , proxiedType); comProxy = ComProxy.Create (outer, tearoffProxy.GetTransparentProxy(), tearoffProxy); return comProxy; } finally { if ((comProxy == null) && (tearoffProxy != null)) ((IDisposable)tearoffProxy).Dispose (); } } bool IProxyCreator.SupportsErrorInfo (ref Guid riid) { if (contractType == null) return false; else { if ((contractType.GUID != riid) && !(CheckDispatch (ref riid))) return false; else return true; } } bool IProxyCreator.SupportsDispatch () { return dispatchEnabled; } bool IProxyCreator.SupportsIntrinsics () { return true; } } } // 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
- CharacterShapingProperties.cs
- InkSerializer.cs
- _DomainName.cs
- AppSettingsSection.cs
- Point3DConverter.cs
- StrokeNodeOperations2.cs
- QueueTransferProtocol.cs
- WeakReferenceKey.cs
- _Rfc2616CacheValidators.cs
- Schema.cs
- DbConnectionHelper.cs
- ExpressionDumper.cs
- Baml2006ReaderContext.cs
- XPathExpr.cs
- ReachPageContentSerializer.cs
- XmlException.cs
- EntityClassGenerator.cs
- XappLauncher.cs
- PtsPage.cs
- BamlLocalizableResource.cs
- HostAdapter.cs
- ScaleTransform3D.cs
- FillBehavior.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- ProfileBuildProvider.cs
- SqlCacheDependency.cs
- ActivityCodeGenerator.cs
- Registry.cs
- SiteMapHierarchicalDataSourceView.cs
- ConstantSlot.cs
- RadioButtonList.cs
- TreeBuilderBamlTranslator.cs
- X509CertificateTrustedIssuerElement.cs
- ListItemConverter.cs
- XmlNamespaceMapping.cs
- shaperfactoryquerycacheentry.cs
- Padding.cs
- TextTreeInsertElementUndoUnit.cs
- HtmlSelect.cs
- ChannelBinding.cs
- ListViewVirtualItemsSelectionRangeChangedEvent.cs
- EventWaitHandle.cs
- CompiledRegexRunner.cs
- RegexInterpreter.cs
- TypeReference.cs
- ConfigurationSectionGroup.cs
- RawStylusInputCustomDataList.cs
- ClientScriptManager.cs
- SHA256Managed.cs
- WebResourceUtil.cs
- CompositeControl.cs
- FileSecurity.cs
- ListViewItemEventArgs.cs
- CustomValidator.cs
- PropertyChangeTracker.cs
- ExpandCollapseProviderWrapper.cs
- FormViewDeletedEventArgs.cs
- DataService.cs
- AvTrace.cs
- TimerEventSubscriptionCollection.cs
- WebReference.cs
- ContentFileHelper.cs
- FixedSOMLineCollection.cs
- OdbcPermission.cs
- XmlIterators.cs
- XmlSchemaComplexType.cs
- Bitmap.cs
- SqlComparer.cs
- Win32Native.cs
- ControlParameter.cs
- XmlSchemaGroupRef.cs
- MetadataPropertyCollection.cs
- DateTimeConstantAttribute.cs
- NavigateEvent.cs
- LogStore.cs
- CheckBoxAutomationPeer.cs
- ReflectionUtil.cs
- EventSinkHelperWriter.cs
- SoapSchemaExporter.cs
- BlurBitmapEffect.cs
- OleDbInfoMessageEvent.cs
- Quad.cs
- SiteOfOriginContainer.cs
- Component.cs
- DiscardableAttribute.cs
- CategoryGridEntry.cs
- LineServices.cs
- CaseStatement.cs
- WizardForm.cs
- RoleManagerSection.cs
- BindingContext.cs
- Message.cs
- infer.cs
- EventSinkHelperWriter.cs
- BlobPersonalizationState.cs
- Propagator.Evaluator.cs
- GeometryDrawing.cs
- SqlFileStream.cs
- XmlTextAttribute.cs
- EncodingNLS.cs