/// <summary> /// Enables an extension object to find out when it has been aggregated. /// Called when the extension is added to the IExtensibleObject.Extensions property. /// </summary> /// <param name="owner"> /// The extensible object that aggregates this extension. /// </param> public void Attach(ServiceHostBase owner) { try { // Setup the ServiceHost for hosting the MetadataService. this.metadataServiceHost = new ServiceHost(typeof(MetadataService)); WebHttpBinding webHttpBinding = new WebHttpBinding(); WebHttpBehavior webHttpBehavior = new WebHttpBehavior(); webHttpBehavior.DefaultBodyStyle = WebMessageBodyStyle.Bare; webHttpBehavior.DefaultOutgoingResponseFormat = WebMessageFormat.Xml; ServiceEndpoint metadataEndpoint = this.metadataServiceHost.AddServiceEndpoint(typeof(IMetadataService), webHttpBinding, this.metadataServiceUri); metadataEndpoint.Behaviors.Add(webHttpBehavior); // Hookup the runtime properties. MetadataServiceRuntimeProperties metadataServiceRuntimeProperties = new MetadataServiceRuntimeProperties(this.metadataServiceUri, this.rootMetadataFileLocation); metadataServiceHost.Extensions.Add(metadataServiceRuntimeProperties); this.metadataServiceHost.Open(); } catch (CommunicationException) { this.metadataServiceHost.Abort(); } catch (TimeoutException) { this.metadataServiceHost.Abort(); } catch (Exception) { this.metadataServiceHost.Abort(); throw; } }
/// <summary> /// This method resolves the instance of MetadataServiceRuntimeProperties class that is /// attached to the current service host and makes it available for the other members in /// this class during its lifetime. /// </summary> /// <remarks> /// This method is invoked by the constructor. /// </remarks> private void ResolveMetadataServiceRuntimeProperties() { Debug.Assert(OperationContext.Current != null, Resources.DebugOperationContextNotInitialized); ServiceHostBase thisHost = OperationContext.Current.Host; this.metadataServiceRuntimeProperties = thisHost.Extensions.Find <MetadataServiceRuntimeProperties>(); Debug.Assert(this.metadataServiceRuntimeProperties != null, ""); }