private static void EnsureMetadataPublishing(ServiceHostBase serviceHost)
        {
            // Ensure the service host has a ServiceMetadataBehavior
            var behaviour = serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (behaviour == null)
            {
                serviceHost.Description.Behaviors.Add(behaviour = new ServiceMetadataBehavior());
            }

            var hostSchemes = serviceHost.Description.Endpoints
                              .Where(s => !s.IsSystemEndpoint && s.Contract.ContractType != typeof(IMetadataExchange))
                              .Select(s => s.Binding.Scheme);

            behaviour.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            behaviour.HttpGetEnabled  = hostSchemes.Contains(Uri.UriSchemeHttp);
            behaviour.HttpsGetEnabled = hostSchemes.Contains(Uri.UriSchemeHttps);

            var mexBindings = hostSchemes.Select(s =>
            {
                switch (s)
                {
                case "http": return(MetadataExchangeBindings.CreateMexHttpBinding());

                case "net.tcp": return(MetadataExchangeBindings.CreateMexTcpBinding());

                case "net.pipe": return(MetadataExchangeBindings.CreateMexNamedPipeBinding());

                default: return(null);
                }
            });

            foreach (var binding in mexBindings.ToList())
            {
                serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, binding, "mex");
            }
        }
 private static void AddEndpoint(ServiceHostBase selfConfiguringHost, EndpointAddress address, ServiceEndpoint se)
 {
     try
     {
         foreach (var operation in se.Contract.Operations.Where(operation => !operation.Behaviors.Contains(typeof(StardustOperationAttribute))))
         {
             operation.Behaviors.Add(new StardustOperationAttribute());
             operation.AddFaultContract();
         }
         selfConfiguringHost.AddServiceEndpoint(se);
     }
     catch (Exception)
     {
         throw new StardustCoreException("Error creating endpoint: " + address);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Adds a service endpoint to the service host with the specified contract, binding and address.
 /// </summary>
 /// <param name="implementedContract">The contract implemented by the endpoint.</param>
 /// <param name="binding">A <see cref="Binding"/> instnace for the endpoint.</param>
 /// <param name="address">The address for the endpoint.</param>
 /// <returns>A <see cref="ServiceEndpoint"/> instance that was added to the service host.</returns>
 public ServiceEndpoint AddServiceEndpoint(string implementedContract, Binding binding, string address)
 {
     return(UnderlyingObject.AddServiceEndpoint(implementedContract, binding, address));
 }
Esempio n. 4
0
 /// <summary>
 /// Enables the UDP discovery.
 /// </summary>
 /// <param name="host">The host.</param>
 public static void EnableUdpDiscovery(this ServiceHostBase host)
 {
     host.AddServiceEndpoint(new UdpAnnouncementEndpoint());
     host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
 }
Esempio n. 5
0
 /// <summary>
 /// Adds a service endpoint to the service host with the specified contract, binding and address.
 /// </summary>
 /// <param name="implementedContract">The contract implemented by the endpoint.</param>
 /// <param name="binding">A <see cref="Binding"/> instnace for the endpoint.</param>
 /// <param name="address">The address for the endpoint.</param>
 /// <returns>A <see cref="ServiceEndpoint"/> instance that was added to the service host.</returns>
 public ServiceEndpoint AddServiceEndpoint(string implementedContract, Binding binding, string address)
 {
     return(_serviceHost.AddServiceEndpoint(implementedContract, binding, address));
 }