Exemple #1
0
        private static ServiceEndpointDescription StartHost <TServiceType, TServiceInterfaceType>
        (
            string name,
            string description,
            HostBindingType bindingType,
            int httpPort,
            int tcpPort,
            string serviceAddressBase)
        {
            var sed = new ServiceEndpointDescription(name, description);

            sed.Binding     = GetBinding <TServiceInterfaceType>(bindingType);
            sed.ServiceHost = new ServiceHost(typeof(TServiceType));
            var endpointAddress = GetEndpointAddress(name, bindingType, tcpPort, httpPort, serviceAddressBase);

            var metadataBehavior = sed.ServiceHost.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (null == metadataBehavior)
            {
                if (bindingType == HostBindingType.BasicHttp ||
                    bindingType == HostBindingType.WSHttp ||
                    bindingType == HostBindingType.WSDualHttp)
                {
                    metadataBehavior = new ServiceMetadataBehavior();
                    metadataBehavior.HttpGetEnabled = true;
                    metadataBehavior.HttpGetUrl     = endpointAddress;
                    sed.ServiceHost.Description.Behaviors.Add(metadataBehavior);
                }
            }

            var debugBehavior = sed.ServiceHost.Description.Behaviors.Find <ServiceDebugBehavior>();

            if (null == debugBehavior)
            {
                debugBehavior = new ServiceDebugBehavior
                {
                    IncludeExceptionDetailInFaults = true
                };

                sed.ServiceHost.Description.Behaviors.Add(debugBehavior);
            }

            sed.ServiceHost.AddServiceEndpoint(typeof(TServiceInterfaceType), sed.Binding, endpointAddress);
            sed.ServiceHost.Open();

            return(sed);
        }
Exemple #2
0
        public ServiceEndpointDescription StartBasicHttpHost <TServiceType, TServiceInterfaceType>(string name, string description)
        {
            Platform.Log(LogLevel.Info, "Starting WCF Shred {0}...", name);

            if (_serviceEndpointDescriptions.ContainsKey(name))
            {
                throw new Exception(String.Format("The service endpoint '{0}' already exists.", name));
            }

            ServiceEndpointDescription sed =
                WcfHelper.StartBasicHttpHost <TServiceType, TServiceInterfaceType>(name, description, SharedHttpPort, ServiceAddressBase);

            _serviceEndpointDescriptions[name] = sed;

            Platform.Log(LogLevel.Info, "WCF Shred {0} is listening at {1}.", name, sed.ServiceHost.Description.Endpoints[0].Address);

            return(sed);
        }
Exemple #3
0
 public static void StopHost(ServiceEndpointDescription sed)
 {
     sed.ServiceHost.Close();
 }