Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Description / MetadataResolver.cs / 1 / MetadataResolver.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Description { using System.Collections.Generic; using System.ServiceModel; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Xml; using XsdNS = System.Xml.Schema; using WsdlNS = System.Web.Services.Description; using System.ServiceModel.Configuration; using System.ServiceModel.Diagnostics; using System.Collections; using System.Diagnostics; using System.Net; using System.Web; using System.Security.Cryptography.X509Certificates; using System.ServiceModel.Channels; using System.ComponentModel; public static class MetadataResolver { public static ServiceEndpointCollection Resolve(Type contract, EndpointAddress address) { if (contract == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contract"); } return Resolve(CreateContractCollection(contract), address); } public static ServiceEndpointCollection Resolve(IEnumerablecontracts, EndpointAddress address) { return Resolve(contracts, address, new MetadataExchangeClient(address)); } public static ServiceEndpointCollection Resolve(IEnumerable contracts, EndpointAddress address, MetadataExchangeClient client) { if (address == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address"); } if (client == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("client"); } if (contracts == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contracts"); } ValidateContracts(contracts); MetadataSet metadataSet = client.GetMetadata(address); return ImportEndpoints(metadataSet, contracts, client); } public static ServiceEndpointCollection Resolve(Type contract, Uri address, MetadataExchangeClientMode mode) { if (contract == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contract"); } return Resolve(CreateContractCollection(contract), address, mode); } public static ServiceEndpointCollection Resolve(IEnumerable contracts, Uri address, MetadataExchangeClientMode mode) { return Resolve(contracts, address, mode, new MetadataExchangeClient(address, mode)); } public static ServiceEndpointCollection Resolve(IEnumerable contracts, Uri address, MetadataExchangeClientMode mode, MetadataExchangeClient client) { if (address == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address"); } MetadataExchangeClientModeHelper.Validate(mode); if (client == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("client"); } if (contracts == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contracts"); } ValidateContracts(contracts); MetadataSet metadataSet = client.GetMetadata(address, mode); return ImportEndpoints(metadataSet, contracts, client); } public static IAsyncResult BeginResolve(Type contract, EndpointAddress address, AsyncCallback callback, object asyncState) { if (contract == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contract"); } return BeginResolve(CreateContractCollection(contract), address, callback, asyncState); } public static IAsyncResult BeginResolve(IEnumerable contracts, EndpointAddress address, AsyncCallback callback, object asyncState) { return BeginResolve(contracts, address, new MetadataExchangeClient(address), callback, asyncState); } public static IAsyncResult BeginResolve(IEnumerable contracts, EndpointAddress address, MetadataExchangeClient client, AsyncCallback callback, object asyncState) { if (address == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address"); } if (client == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("client"); } if (contracts == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contracts"); } ValidateContracts(contracts); return new AsyncMetadataResolverHelper(address, MetadataExchangeClientMode.MetadataExchange, client, contracts, callback, asyncState); } public static IAsyncResult BeginResolve(Type contract, Uri address, MetadataExchangeClientMode mode, AsyncCallback callback, object asyncState) { if (contract == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contract"); } return BeginResolve(CreateContractCollection(contract), address, mode, callback, asyncState); } public static IAsyncResult BeginResolve(IEnumerable contracts, Uri address, MetadataExchangeClientMode mode, AsyncCallback callback, object asyncState) { return BeginResolve(contracts, address, mode, new MetadataExchangeClient(address, mode), callback, asyncState); } public static IAsyncResult BeginResolve(IEnumerable contracts, Uri address, MetadataExchangeClientMode mode, MetadataExchangeClient client, AsyncCallback callback, object asyncState) { if (address == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address"); } MetadataExchangeClientModeHelper.Validate(mode); if (client == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("client"); } if (contracts == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contracts"); } ValidateContracts(contracts); return new AsyncMetadataResolverHelper(new EndpointAddress(address), mode, client, contracts, callback, asyncState); } public static ServiceEndpointCollection EndResolve(IAsyncResult result) { return AsyncMetadataResolverHelper.EndAsyncCall(result); } class AsyncMetadataResolverHelper : AsyncResult { MetadataExchangeClient client; EndpointAddress address; ServiceEndpointCollection endpointCollection; MetadataExchangeClientMode mode; IEnumerable knownContracts; internal AsyncMetadataResolverHelper(EndpointAddress address, MetadataExchangeClientMode mode, MetadataExchangeClient client, IEnumerable knownContracts, AsyncCallback callback, object asyncState) : base(callback, asyncState) { this.address = address; this.client = client; this.mode = mode; this.knownContracts = knownContracts; GetMetadataSetAsync(); } internal void GetMetadataSetAsync() { IAsyncResult result; if (this.mode == MetadataExchangeClientMode.HttpGet) { result = this.client.BeginGetMetadata(this.address.Uri, MetadataExchangeClientMode.HttpGet, DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(this.EndGetMetadataSet)), null); } else { result = this.client.BeginGetMetadata(this.address, DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(this.EndGetMetadataSet)), null); } if (result.CompletedSynchronously) { HandleResult(result); this.Complete(true); } } internal void EndGetMetadataSet(IAsyncResult result) { if (result.CompletedSynchronously) return; Exception exception = null; try { HandleResult(result); } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) throw; exception = e; } this.Complete(false, exception); } private void HandleResult(IAsyncResult result) { MetadataSet metadataSet = this.client.EndGetMetadata(result); endpointCollection = ImportEndpoints(metadataSet, knownContracts, this.client); } internal static ServiceEndpointCollection EndAsyncCall(IAsyncResult result) { AsyncMetadataResolverHelper helper = AsyncResult.End (result); return helper.endpointCollection; } } private static ServiceEndpointCollection ImportEndpoints(MetadataSet metadataSet, IEnumerable contracts, MetadataExchangeClient client) { ServiceEndpointCollection endpoints = new ServiceEndpointCollection(); WsdlImporter importer = new WsdlImporter(metadataSet); // remember the original proxy so user doesn't need to set it again importer.State.Add(MetadataExchangeClient.MetadataExchangeClientKey, client); foreach (ContractDescription cd in contracts) { importer.KnownContracts.Add(WsdlExporter.WsdlNamingHelper.GetPortTypeQName(cd), cd); } foreach(ContractDescription cd in contracts) { ServiceEndpointCollection contractEndpoints; contractEndpoints = importer.ImportEndpoints(cd); foreach (ServiceEndpoint se in contractEndpoints) { endpoints.Add(se); } } //Trace all warnings and errors if (importer.Errors.Count > 0) { TraceWsdlImportErrors(importer); } return endpoints; } static void TraceWsdlImportErrors(WsdlImporter importer) { foreach (MetadataConversionError error in importer.Errors) { if (DiagnosticUtility.ShouldTraceWarning) { Hashtable h = new Hashtable(2); h.Add("IsWarning", error.IsWarning); h.Add("Message", error.Message); TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.WsmexNonCriticalWsdlExportError, new DictionaryTraceRecord(h), null, null); } } } private static void ValidateContracts(IEnumerable contracts) { bool isEmpty = true; Collection qnames = new Collection (); foreach (ContractDescription cd in contracts) { isEmpty = false; if (cd == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SFxMetadataResolverKnownContractsCannotContainNull)); } XmlQualifiedName qname = WsdlExporter.WsdlNamingHelper.GetPortTypeQName(cd); if (qnames.Contains(qname)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SFxMetadataResolverKnownContractsUniqueQNames, qname.Name, qname.Namespace)); } qnames.Add(qname); } if (isEmpty) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SFxMetadataResolverKnownContractsArgumentCannotBeEmpty)); } } private static Collection CreateContractCollection(Type contract) { Collection contracts = new Collection (); contracts.Add(ContractDescription.GetContract(contract)); return contracts; } } } // 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
- KeyValueInternalCollection.cs
- EditCommandColumn.cs
- ExtensionDataReader.cs
- ServicePointManager.cs
- DeflateStream.cs
- SegmentInfo.cs
- SplineQuaternionKeyFrame.cs
- ToolStripLocationCancelEventArgs.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- SID.cs
- TypeGeneratedEventArgs.cs
- Int16.cs
- ByteStreamGeometryContext.cs
- DtrList.cs
- ZoneLinkButton.cs
- WindowVisualStateTracker.cs
- ColorInterpolationModeValidation.cs
- PackagingUtilities.cs
- EmbeddedMailObjectCollectionEditor.cs
- ClientScriptManager.cs
- VarRemapper.cs
- SecurityVerifiedMessage.cs
- ChtmlMobileTextWriter.cs
- TableLayoutSettingsTypeConverter.cs
- XmlSchemaSimpleContentRestriction.cs
- DataViewSettingCollection.cs
- NameHandler.cs
- RegexCompilationInfo.cs
- XmlC14NWriter.cs
- PKCS1MaskGenerationMethod.cs
- XslVisitor.cs
- InterleavedZipPartStream.cs
- ControlBuilderAttribute.cs
- WebResourceAttribute.cs
- XmlSchemaAttribute.cs
- TableAdapterManagerNameHandler.cs
- UnitySerializationHolder.cs
- SyndicationDeserializer.cs
- StatusBarAutomationPeer.cs
- SiteIdentityPermission.cs
- Conditional.cs
- RemotingSurrogateSelector.cs
- ManipulationVelocities.cs
- SchemaCollectionPreprocessor.cs
- DockPatternIdentifiers.cs
- Int16AnimationBase.cs
- HTTPNotFoundHandler.cs
- ConsumerConnectionPoint.cs
- WebServiceFaultDesigner.cs
- ByteStack.cs
- NotificationContext.cs
- RelationshipEntry.cs
- UnsafeNativeMethods.cs
- ErrorEventArgs.cs
- ConnectionProviderAttribute.cs
- LostFocusEventManager.cs
- PeerApplication.cs
- TextBoxBaseDesigner.cs
- SelectorItemAutomationPeer.cs
- RegexFCD.cs
- Opcode.cs
- PrivilegedConfigurationManager.cs
- XamlWriterExtensions.cs
- SymmetricCryptoHandle.cs
- SimpleBitVector32.cs
- HitTestParameters.cs
- HandledMouseEvent.cs
- BamlBinaryReader.cs
- ObjectQueryExecutionPlan.cs
- LogSwitch.cs
- HandlerWithFactory.cs
- ExtensionSimplifierMarkupObject.cs
- XmlStreamNodeWriter.cs
- TypeLibConverter.cs
- X509Certificate.cs
- InstalledFontCollection.cs
- XPathAxisIterator.cs
- PrinterSettings.cs
- WebPart.cs
- OpCopier.cs
- SystemIcons.cs
- DbReferenceCollection.cs
- EntityDataSourceValidationException.cs
- DeclarativeCatalogPart.cs
- XmlMemberMapping.cs
- SamlConditions.cs
- WebHttpBehavior.cs
- TextSimpleMarkerProperties.cs
- DetailsViewPagerRow.cs
- SecureStringHasher.cs
- ZipFileInfo.cs
- RouteParser.cs
- SafeFileMapViewHandle.cs
- FocusTracker.cs
- RightsManagementEncryptedStream.cs
- XmlTextWriter.cs
- ImplicitInputBrush.cs
- TableLayoutRowStyleCollection.cs
- sqlinternaltransaction.cs
- InstalledVoice.cs