/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <returns>The endpoints that were created.</returns> public override IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost) { Debug.Assert(this.Name != null, "Name has not been set."); Debug.Assert(this.domainDataServiceMetadata == null, "this.domainDataServiceMetadata == null"); if (description.Attributes[typeof(EnableClientAccessAttribute)] != null) { // The metadata object will tell us which operations we should expose for the OData end point. this.domainDataServiceMetadata = new OData.DomainDataServiceMetadata(description); // The OData endpoint doesn't expose all operations in the DomainService, but only operations with parameter and return types // which are supported by the data service. WCF doesn't allow us to create a contract without any operation. if (this.domainDataServiceMetadata.Sets.Count > 0 || this.domainDataServiceMetadata.ServiceOperations.Count > 0) { // Infer the contract from Domain service description. ContractDescription contract = this.CreateContract(description); // Make endpoints that expose the inferred contract on the given base addresses. foreach (Uri address in serviceHost.BaseAddresses) { yield return this.CreateEndpointForAddress(description, contract, address); } } } }
/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <returns>The endpoints that were created.</returns> public override IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost) { ContractDescription contract = this.CreateContract(description); List<ServiceEndpoint> endpoints = new List<ServiceEndpoint>(); foreach (Uri address in serviceHost.BaseAddresses) { endpoints.Add(this.CreateEndpointForAddress(contract, address)); } return endpoints; }
/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <returns>The endpoints that were created.</returns> public override IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost) { ContractDescription contract = this.CreateContract(description); contract.Behaviors.Add(new ServiceMetadataContractBehavior() { MetadataGenerationDisabled = true }); List<ServiceEndpoint> endpoints = new List<ServiceEndpoint>(); foreach (Uri address in serviceHost.BaseAddresses) { endpoints.Add(this.CreateEndpointForAddress(contract, address)); } return endpoints; }
/// <summary> /// Creates a description of the service hosted. /// </summary> /// <param name="implementedContracts"> /// The <see cref="IDictionary<TKey,TValue>"/> with key pairs of /// type (string, <see cref="ContractDescription"/>) that contains the /// keyed-contracts of the hosted service that have been implemented. /// </param> /// <returns>A <see cref="ServiceDescription"/> of the hosted service.</returns> protected override ServiceDescription CreateDescription(out IDictionary <string, ContractDescription> implementedContracts) { try { Type domainServiceType = this._domainServiceDescription.DomainServiceType; ServiceDescription serviceDesc = ServiceDescription.GetService(domainServiceType); implementedContracts = new Dictionary <string, ContractDescription>(); DomainServicesSection config = (DomainServicesSection)WebConfigurationManager.GetSection("system.serviceModel/domainServices"); if (config == null) { // Make sure we have a config instance, as that's where we put our default configuration. If we don't do this, our // binary endpoint won't be used when someone doesn't have a <domainServices/> section in their web.config. config = new DomainServicesSection(); config.InitializeDefaultInternal(); } foreach (ProviderSettings provider in config.Endpoints) { DomainServiceEndpointFactory endpointFactory = DomainServiceHost.CreateEndpointFactoryInstance(provider); foreach (ServiceEndpoint endpoint in endpointFactory.CreateEndpoints(this._domainServiceDescription, this)) { string contractName = endpoint.Contract.ConfigurationName; ContractDescription contract; if (implementedContracts.TryGetValue(contractName, out contract) && contract != endpoint.Contract) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.DomainServiceHost_DuplicateContractName, contract.ConfigurationName)); } // Register the contract. implementedContracts[endpoint.Contract.ConfigurationName] = endpoint.Contract; // Register the endpoint. serviceDesc.Endpoints.Add(endpoint); } } return(serviceDesc); } catch (Exception ex) { DiagnosticUtility.ServiceException(ex); throw; } }
/// <summary> /// Creates a set of WCF REST service endpoints in the <see cref="OpenRiaServices.DomainServices.Hosting.DomainServiceHost"/> which /// expose traces of WCF services in the ATOM, XML, or HTML format. One WCF REST endpoint is added for each HTTP or HTTPS base address from the specified serviceHost. /// The address of the endpoint is obtained by appending the name of the TracingDomainServiceEndpointFactory as specified in the domainServices section of the configuration file /// to the base address. Furthermore, the UriTemplate of each of the endpoints is specified by the <see cref="WcfTraceService"/> service contract and allows for selection of the /// response contract between ATOM, XML, or HTML. /// </summary> /// <param name="description">WCF RIA service description.</param> /// <param name="serviceHost">Service host to which endpoints will be added.</param> /// <returns>The collection of endpoints.</returns> public override IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost) { if (serviceHost == null) { throw new ArgumentNullException("serviceHost"); } if (this.Parameters["maxEntries"] != null) { int maxEntries; if (int.TryParse(this.Parameters["maxEntries"], out maxEntries)) { InMemoryTraceListener.MaxEntries = maxEntries; } else { throw new InvalidOperationException(Resx.MaxEntriesAttributeMustBeAPositiveInteger); } } ContractDescription contract = ContractDescription.GetContract(typeof(WcfTraceService)); contract.Behaviors.Add(new ServiceMetadataContractBehavior { MetadataGenerationDisabled = true }); List<ServiceEndpoint> tracingEndpoints = new List<ServiceEndpoint>(); foreach (Uri baseAddress in serviceHost.BaseAddresses) { WebHttpBinding binding = new WebHttpBinding(); if (baseAddress.Scheme.Equals(Uri.UriSchemeHttps)) { binding.Security.Mode = WebHttpSecurityMode.Transport; } else if (!baseAddress.Scheme.Equals(Uri.UriSchemeHttp)) { continue; } ServiceEndpoint endpoint = new ServiceEndpoint(contract, binding, new EndpointAddress(baseAddress.OriginalString + "/" + this.Name)); endpoint.Behaviors.Add(new WebHttpBehavior()); endpoint.Behaviors.Add(new TracingEndpointBehavior { ServiceHost = serviceHost }); tracingEndpoints.Add(endpoint); } return tracingEndpoints; }
/// <summary> /// Creates a description of the service hosted. /// </summary> /// <param name="implementedContracts"> /// The <see cref="IDictionary<TKey,TValue>"/> with key pairs of /// type (string, <see cref="ContractDescription"/>) that contains the /// keyed-contracts of the hosted service that have been implemented. /// </param> /// <returns>A <see cref="ServiceDescription"/> of the hosted service.</returns> protected override ServiceDescription CreateDescription(out IDictionary <string, ContractDescription> implementedContracts) { try { Type domainServiceType = this._domainServiceDescription.DomainServiceType; ServiceDescription serviceDesc = ServiceDescription.GetService(domainServiceType); implementedContracts = new Dictionary <string, ContractDescription>(); DomainServicesSection config = DomainServicesSection.Current; foreach (ProviderSettings provider in config.Endpoints) { DomainServiceEndpointFactory endpointFactory = DomainServiceHost.CreateEndpointFactoryInstance(provider); foreach (ServiceEndpoint endpoint in endpointFactory.CreateEndpoints(this._domainServiceDescription, this)) { string contractName = endpoint.Contract.ConfigurationName; ContractDescription contract; if (implementedContracts.TryGetValue(contractName, out contract) && contract != endpoint.Contract) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.DomainServiceHost_DuplicateContractName, contract.ConfigurationName)); } // Register the contract. implementedContracts[endpoint.Contract.ConfigurationName] = endpoint.Contract; // Register the endpoint. serviceDesc.Endpoints.Add(endpoint); } } return(serviceDesc); } catch (Exception ex) { DiagnosticUtility.ServiceException(ex); throw; } }
/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <returns>The endpoints that were created.</returns> public override IEnumerable <ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost) { ContractDescription contract = this.CreateContract(description); List <ServiceEndpoint> endpoints = new List <ServiceEndpoint>(); foreach (Uri address in serviceHost.BaseAddresses) { endpoints.Add(this.CreateEndpointForAddress(contract, address)); } return(endpoints); }
/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <returns>The endpoints that were created.</returns> public abstract IEnumerable <ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost);
/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <param name="contractDescription">the default domain serice contract description</param> /// <returns>The endpoints that were created.</returns> public virtual IEnumerable <ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost, ContractDescription contractDescription) { var endpoints = new List <ServiceEndpoint>(); foreach (Uri address in serviceHost.BaseAddresses) { endpoints.Add(this.CreateEndpointForAddress(contractDescription, address)); } return(endpoints); }
/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <returns>The endpoints that were created.</returns> public override IEnumerable <ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost) { ContractDescription contract = this.CreateContract(description); contract.Behaviors.Add(new ServiceMetadataContractBehavior() { MetadataGenerationDisabled = true }); List <ServiceEndpoint> endpoints = new List <ServiceEndpoint>(); foreach (Uri address in serviceHost.BaseAddresses) { endpoints.Add(this.CreateEndpointForAddress(contract, address)); } return(endpoints); }
/// <summary> /// Creates a set of WCF REST service endpoints in the <see cref="OpenRiaServices.DomainServices.Hosting.DomainServiceHost"/> which /// expose traces of WCF services in the ATOM, XML, or HTML format. One WCF REST endpoint is added for each HTTP or HTTPS base address from the specified serviceHost. /// The address of the endpoint is obtained by appending the name of the TracingDomainServiceEndpointFactory as specified in the domainServices section of the configuration file /// to the base address. Furthermore, the UriTemplate of each of the endpoints is specified by the <see cref="WcfTraceService"/> service contract and allows for selection of the /// response contract between ATOM, XML, or HTML. /// </summary> /// <param name="description">WCF RIA service description.</param> /// <param name="serviceHost">Service host to which endpoints will be added.</param> /// <returns>The collection of endpoints.</returns> public override IEnumerable <ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost) { if (serviceHost == null) { throw new ArgumentNullException("serviceHost"); } if (this.Parameters["maxEntries"] != null) { int maxEntries; if (int.TryParse(this.Parameters["maxEntries"], out maxEntries)) { InMemoryTraceListener.MaxEntries = maxEntries; } else { throw new InvalidOperationException(Resx.MaxEntriesAttributeMustBeAPositiveInteger); } } ContractDescription contract = ContractDescription.GetContract(typeof(WcfTraceService)); contract.Behaviors.Add(new ServiceMetadataContractBehavior { MetadataGenerationDisabled = true }); List <ServiceEndpoint> tracingEndpoints = new List <ServiceEndpoint>(); foreach (Uri baseAddress in serviceHost.BaseAddresses) { WebHttpBinding binding = new WebHttpBinding(); if (baseAddress.Scheme.Equals(Uri.UriSchemeHttps)) { binding.Security.Mode = WebHttpSecurityMode.Transport; } else if (!baseAddress.Scheme.Equals(Uri.UriSchemeHttp)) { continue; } ServiceEndpoint endpoint = new ServiceEndpoint(contract, binding, new EndpointAddress(baseAddress.OriginalString + "/" + this.Name)); endpoint.Behaviors.Add(new WebHttpBehavior()); endpoint.Behaviors.Add(new TracingEndpointBehavior { ServiceHost = serviceHost }); tracingEndpoints.Add(endpoint); } return(tracingEndpoints); }
/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <returns>The endpoints that were created.</returns> public override IEnumerable <ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost) { Debug.Assert(this.Name != null, "Name has not been set."); Debug.Assert(this.domainDataServiceMetadata == null, "this.domainDataServiceMetadata == null"); if (description.Attributes[typeof(EnableClientAccessAttribute)] != null) { // The metadata object will tell us which operations we should expose for the OData end point. this.domainDataServiceMetadata = new OData.DomainDataServiceMetadata(description); // The OData endpoint doesn't expose all operations in the DomainService, but only operations with parameter and return types // which are supported by the data service. WCF doesn't allow us to create a contract without any operation. if (this.domainDataServiceMetadata.Sets.Count > 0 || this.domainDataServiceMetadata.ServiceOperations.Count > 0) { // Infer the contract from Domain service description. ContractDescription contract = this.CreateContract(description); // Make endpoints that expose the inferred contract on the given base addresses. foreach (Uri address in serviceHost.BaseAddresses) { yield return(this.CreateEndpointForAddress(description, contract, address)); } } } }
/// <summary> /// Creates endpoints based on the specified description. /// </summary> /// <param name="description">The <see cref="DomainServiceDescription"/> of the <see cref="DomainService"/> to create the endpoints for.</param> /// <param name="serviceHost">The service host for which the endpoints will be created.</param> /// <returns>The endpoints that were created.</returns> public abstract IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost);