public ServiceEndpoint GetServiceBinding <T>(string serviceName, string url) { var cd = GetContractDescription <T>(); var endpoint = GetEndpointConfig(serviceName); return(new ServiceEndpoint(cd, ServiceHostHelper.CreateBinding(endpoint.First()), GetEndpointAddress <T>(endpoint.First().Address))); }
public SmartCardATMServiceHost() { string addess = ServiceHostHelper.GetBaseAddresses(ServiceHostEnum.ATM_HOST); var binding = new NetTcpBinding(); serviceHost = new ServiceHost(typeof(SCSATMProvider)); serviceHost.AddServiceEndpoint(typeof(IATMService), binding, new Uri(addess)); }
private static Binding CreateBinding(Endpoint serviceInterfaceEndpoint) { try { return(ServiceHostHelper.CreateBinding(serviceInterfaceEndpoint)); } catch (Exception ex) { throw new StardustCoreException(string.Format("Failed to create binding for protocol {0}", serviceInterfaceEndpoint.EndpointName), ex); } }
public SmartCardReplicatorServiceHost() { string addess = ServiceHostHelper.GetBaseAddresses(ServiceHostEnum.REPLICATOR_HOST); NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; serviceHost = new ServiceHost(typeof(SCSReplicatorProvider)); serviceHost.AddServiceEndpoint(typeof(IReplicateService), binding, new Uri(addess)); }
public void ConfigureServiceHost(ServiceHost selfConfiguringHost, Type serviceType) { var serviceInterfaces = serviceType.GetInterfaces(); var serviceName = ServiceHostHelper.GetServiceName(serviceType, serviceInterfaces); var serviceRootUrl = GetRuntime().Context.GetEnvironmentConfiguration().GetConfigParameter(ServiceHostHelper.GetServiceRootUrl(GetRuntime(), serviceType, serviceInterfaces)); var contractDescriptions = new Dictionary <Type, ContractDescription>(); foreach (var serviceInterfaceEndpoint in GetEndpoints(serviceName)) { if (serviceInterfaceEndpoint.Ignore) { continue; } var address = ServiceHostHelper.EndpointAddress(serviceName, serviceInterfaceEndpoint, serviceRootUrl); var binding = CreateBinding(serviceInterfaceEndpoint); if (serviceInterfaces.IsNull()) { throw new StardustCoreException("Service interface not found"); } foreach (var type in serviceInterfaces) { if (ServiceHostHelper.InterfaceIsNotServiceContract(type)) { continue; } if (!LegalEndpoint(type, serviceInterfaceEndpoint.EndpointName)) { continue; } AddContractDescription(contractDescriptions, type); var cd = contractDescriptions[type]; cd.Namespace = "http://service.dyn.no/" + type.Name; try { var se = CreateEndpoint(binding, address, cd, serviceInterfaceEndpoint); se.Behaviors.Add(new InspectorInserter()); if (binding is WebHttpBinding) { Resolver.Activate <WebBehaviorProvider>().ApplyBehavior(se); } AddEndpoint(selfConfiguringHost, address, se); } catch (Exception ex) { throw new StardustCoreException("Failed to create and add endpoint", ex); } } } }
private IEnumerable <Endpoint> GetEndpoints(string serviceName) { try { var endpoints = from ep in GetRuntime().Context .GetEndpointConfiguration(serviceName).Endpoints where ServiceHostHelper.EndpointIsSupported(ep.BindingType) select ep; return(endpoints); } catch (Exception ex) { throw new StardustCoreException(string.Format("Failed to retrieve endpoints for service {0}", serviceName), ex); } }
private static void Main(string[] args) { try { var serviceNamespace = ConfigurationManager.AppSettings.Get("Microsoft.ServiceBus.ConnectionString"); var servicePaths = new Dictionary <Type, string> { { typeof(PersonService), "person" }, { typeof(ImageService), "image" } }; var hosts = new BlockingCollection <WebServiceHost>(); var helper = new ServiceHostHelper(); Console.WriteLine("Establishing connection to Azure Service Bus.."); Parallel.ForEach(servicePaths, (path) => { var hostTuple = helper.InitServiceHost(path.Key, "https", serviceNamespace, path.Value); hosts.Add(hostTuple.Item1); Console.WriteLine("listening on " + hostTuple.Item2); }); Console.WriteLine("Ready !"); Console.WriteLine(); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); Parallel.ForEach(hosts, (host) => host.Close()); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); } }