/// <summary> /// Adds the HTTPS. /// </summary> /// <param name="services">The services collection used to configure the Insolvency Service.</param> /// <param name="codePackageActivationContext">The code package activation context.</param> /// <param name="configuration">The configuration settings used in the Insolvency Service.</param> public static void AddHttps( this IServiceCollection services, ICodePackageActivationContext codePackageActivationContext, IConfiguration configuration) { if (codePackageActivationContext == null) { return; } var endpoints = codePackageActivationContext.GetEndpoints(); if (endpoints.Count == 0) { return; } EndpointResourceDescription endpointResourceDescription = endpoints.FirstOrDefault(endpoint => endpoint.Protocol == EndpointProtocol.Https); if (endpointResourceDescription == null) { return; } using (var x509Store = new X509StoreWrapper()) { services.AddHttpsWithCertificate(x509Store, configuration, endpointResourceDescription.Port); } }
/// <summary> /// Opens the communication listener /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public Task <string> OpenAsync(CancellationToken cancellationToken) { EndpointResourceDescription serviceEndpoint = _serviceInitializationParameters.CodePackageActivationContext.GetEndpoint(_endpointName); int port = serviceEndpoint.Port; string appRoot = string.IsNullOrWhiteSpace(_appRoot) ? string.Empty : _appRoot.TrimEnd('/') + '/'; var statefulServiceInitializationParameters = _serviceInitializationParameters as StatefulServiceInitializationParameters; if (statefulServiceInitializationParameters != null) { _listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}{2}/{3}/{4}", port, appRoot, statefulServiceInitializationParameters.PartitionId, statefulServiceInitializationParameters.ReplicaId, Guid.NewGuid()); } else if (_serviceInitializationParameters is StatelessServiceInitializationParameters) { _listeningAddress = string.Format(CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, appRoot); } else { throw new InvalidOperationException(); } _serverHandle = WebApp.Start(_listeningAddress, appBuilder => _startup.Configuration(appBuilder)); string resultAddress = _listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); ServiceEventSource.Current.Message("Listening on {0}", resultAddress); return(Task.FromResult(resultAddress)); }
private async Task RunTcpListener(EndpointResourceDescription endpoint) { var tcpListener = TcpListener.Create(endpoint.Port); try { tcpListener.Start(); while (!_tcpListenerCancellation.IsCancellationRequested) { var tcpClient = await tcpListener.AcceptTcpClientAsync(); try { await CreateAdcClient(tcpClient); } catch (Exception exception) { ServiceEventSource.Current.ServiceRequestFailed(tcpClient.Client.RemoteEndPoint.ToString(), exception.ToString()); tcpClient.Close(); } } } catch (Exception exception) { ServiceEventSource.Current.TcpExchangeFailed(exception.ToString()); } finally { tcpListener.Stop(); } }
public Task <string> OpenAsync(CancellationToken cancellationToken) { ServiceEventSource.Current.Message("Initialize"); EndpointResourceDescription serviceEndpoint = this.serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("WebEndpoint"); int port = serviceEndpoint.Port; this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/'); this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); ServiceEventSource.Current.Message("Starting web server on {0}", this.listeningAddress); try { this.webHost = new WebHostBuilder() .UseKestrel() .UseStartup <Startup>() .UseUrls(this.listeningAddress) .Build(); this.webHost.Start(); } catch (Exception ex) { ServiceEventSource.Current.ServiceWebHostBuilderFailed(ex); } return(Task.FromResult(this.publishAddress)); }
public NginxCommunicationListener(string endpointName, IKillExeProcess process, StatelessServiceContext context) { _process = process; _context = context; _endpoint = _context.CodePackageActivationContext.GetEndpoint(endpointName); }
private ICommunicationListener CreateInternalListener(ServiceContext context) { // Partition replica's URL is the node's IP, port, PartitionId, ReplicaId, Guid EndpointResourceDescription internalEndpoint = context.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); // Multiple replicas of this service may be hosted on the same machine, // so this address needs to be unique to the replica which is why we have partition ID + replica ID in the URL. // HttpListener can listen on multiple addresses on the same port as long as the URL prefix is unique. // The extra GUID is there for an advanced case where secondary replicas also listen for read-only requests. // When that's the case, we want to make sure that a new unique address is used when transitioning from primary to secondary // to force clients to re-resolve the address. // '+' is used as the address here so that the replica listens on all available hosts (IP, FQDM, localhost, etc.) string uriPrefix = String.Format( "{0}://+:{1}/{2}/{3}-{4}/", internalEndpoint.Protocol, internalEndpoint.Port, context.PartitionId, context.ReplicaOrInstanceId, Guid.NewGuid()); string nodeIP = FabricRuntime.GetNodeContext().IPAddressOrFQDN; // The published URL is slightly different from the listening URL prefix. // The listening URL is given to HttpListener. // The published URL is the URL that is published to the Service Fabric Naming Service, // which is used for service discovery. Clients will ask for this address through that discovery service. // The address that clients get needs to have the actual IP or FQDN of the node in order to connect, // so we need to replace '+' with the node's IP or FQDN. string uriPublished = uriPrefix.Replace("+", nodeIP); return(new HttpCommunicationListener(uriPrefix, uriPublished, this.ProcessInternalRequest)); }
private string CreatePublicAddress() { EndpointResourceDescription endpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint(this.endpointName); int port = endpoint.Port; string lower = endpoint.Protocol.ToString().ToLower(); if (this.serviceContext is StatefulServiceContext) { StatefulServiceContext serviceContext = this.serviceContext as StatefulServiceContext; string str1; if (!string.IsNullOrWhiteSpace(this.appRoot)) { str1 = this.appRoot.TrimEnd('/') + "/"; } else { str1 = string.Empty; } string str2 = str1; this.listeningAddress = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}://+:{1}/{2}{3}/{4}/{5}", (object)lower, (object)port, (object)str2, (object)serviceContext.PartitionId, (object)serviceContext.ReplicaId, (object)Guid.NewGuid()); } else { if (!(this.serviceContext is StatelessServiceContext)) { throw new InvalidOperationException(string.Format("'{0}' could not be handled", (object)typeof(ServiceContext).Name)); } this.listeningAddress = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}://+:{1}/{2}", (object)lower, (object)port, (object)this.appRoot); } return(this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN)); }
public GenericHostCommunicationListener(EndpointResourceDescription endpoint, NodeContext nodeContext, Func <EndpointResourceDescription, IHostBuilder> builder, ServiceContext serviceContext) { Endpoint = endpoint; NodeContext = nodeContext; HostBuilderFactory = builder; ServiceContext = serviceContext; }
Task <string> ICommunicationListener.OpenAsync(CancellationToken cancellationToken) { string ip = this.serviceContext.NodeContext.IPAddressOrFQDN; EndpointResourceDescription serviceEndpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint(this.endpointName); EndpointProtocol protocol = serviceEndpoint.Protocol; int port = serviceEndpoint.Port; string host = "+"; string listenUrl; string path = this.appPath != null?this.appPath.TrimEnd('/') + "/" : ""; if (this.serviceContext is StatefulServiceContext) { StatefulServiceContext statefulContext = this.serviceContext as StatefulServiceContext; listenUrl = $"{serviceEndpoint.Protocol}://{host}:{serviceEndpoint.Port}/{path}{statefulContext.PartitionId}/{statefulContext.ReplicaId}/{Guid.NewGuid()}"; } else { listenUrl = $"{serviceEndpoint.Protocol}://{host}:{serviceEndpoint.Port}/{path}"; } this.webHost = this.build(listenUrl); this.webHost.Start(); return(Task.FromResult(listenUrl.Replace("://+", "://" + ip))); }
public Task <string> OpenAsync(CancellationToken cancellationToken) { ServiceEventSource.Current.Message("Initialize"); EndpointResourceDescription serviceEndpoint = serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/'); this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); ServiceEventSource.Current.Message("Starting web server on {0}", this.listeningAddress); this.webSocketApp = new WebSocketApp(this.visualObjectsBox); this.webApp = WebApp.Start <Startup>(this.listeningAddress); this.webSocketApp.Start(this.listeningAddress + this.webSocketRoot); return(Task.FromResult(this.publishAddress)); }
public RedisHost(StatelessServiceContext serviceContext) : base(serviceContext) { EndpointResourceDescription endpoint = serviceContext.CodePackageActivationContext.GetEndpoint("RedisEndpoint"); _redisPort = endpoint.Port; }
public Task <string> OpenAsync(CancellationToken cancellationToken) { EndpointResourceDescription serviceEndpoint = serviceContext.CodePackageActivationContext.GetEndpoint(endpointName); var protocol = serviceEndpoint.Protocol; int port = serviceEndpoint.Port; listeningAddress = string.Format( CultureInfo.InvariantCulture, "{0}://+:{1}/{2}", protocol, port, string.IsNullOrWhiteSpace(appRoot) ? string.Empty : appRoot.TrimEnd('/') + '/' ); publishAddress = listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); try { eventSource.Message("Starting web server on " + listeningAddress); webApp = WebApp.Start(listeningAddress, appBuilder => startup.Invoke(appBuilder)); eventSource.Message("Listening on " + publishAddress); return(Task.FromResult(publishAddress)); } catch (Exception e) { eventSource.Message("Web server failed to open endpoint {0}. {1}", endpointName, e.ToString()); StopWebServer(); throw; } }
public SimpleCommunicationListener(StatefulServiceContext context, string endpointName, Func <object, Task> messageHandler, Action <Exception> exceptionHandler) { this.messageHandler = messageHandler; this.exceptionHandler = exceptionHandler; // need to extract host and port from context and environment //int minWorkerThreads; //int minCompletionPortThreads; //ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads); //ThreadPool.SetMinThreads(minWorkerThreads, Math.Max(5, minCompletionPortThreads)); EndpointResourceDescription endpointDesc = context.CodePackageActivationContext.GetEndpoint(endpointName); port = endpointDesc.Port; var node = FabricRuntime.GetNodeContext(); host = FabricRuntime.GetNodeContext().IPAddressOrFQDN; if (host == "localhost") { var hostEntry = Dns.GetHostEntry(Dns.GetHostName()); var internalIP = hostEntry.AddressList.ToList().FirstOrDefault(t => t.AddressFamily == AddressFamily.InterNetwork); if (internalIP != null) { host = internalIP.ToString(); } } listeningAddress = $"tcp://+:{endpointDesc.Port}"; publicAddress = listeningAddress.Replace("+", host); this.serverControl = new CancellationTokenSource(); }
public Task <string> OpenAsync(CancellationToken cancellationToken) { Logger.Debug(nameof(this.OpenAsync)); try { EndpointResourceDescription serviceEndpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; this.listeningAddress = String.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/'); this.serverHandle = WebApp.Start(this.listeningAddress, appBuilder => this.startup.Configuration(appBuilder)); string resultAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); Logger.Debug("Listening on {0}", resultAddress); return(Task.FromResult(resultAddress)); } catch (Exception ex) { Logger.Error(ex, nameof(this.OpenAsync)); throw; } }
private ICommunicationListener CreateInputListener(StatelessServiceInitializationParameters args) { EndpointResourceDescription inputEndpoint = args.CodePackageActivationContext.GetEndpoint("FEEndpoint"); string uriPrefix = String.Format("{0}://+:{1}/", inputEndpoint.Protocol, inputEndpoint.Port); string uriPublished = uriPrefix.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); return(new HttpCommunicationListener(uriPrefix, uriPublished, this)); }
public OwinCommunicationListener( Action <IAppBuilder, StatelessServiceContext> startup, StatelessServiceContext serviceContext, EndpointResourceDescription endpoint) { this.startup = startup; this.serviceContext = serviceContext; this.endpoint = endpoint; }
public Task <string> OpenAsync(CancellationToken cancellationToken) { ServiceEventSource.Current.Message("Initialize"); EndpointResourceDescription serviceEndpoint = this.serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/'); this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); ServiceEventSource.Current.Message("Starting web server on {0}", this.listeningAddress); try { this.webHost = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup <Startup>() .UseUrls(this.listeningAddress) .ConfigureAppConfiguration((hostingContext, config) => { config .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath) .AddJsonFile("appsettings.json", false, true) .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true) .AddJsonFile("ocelot.json", false, false) .AddEnvironmentVariables(); }) .ConfigureLogging((hostingContext, logging) => { logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); logging.AddConsole(); }) .ConfigureServices(s => { s.AddOcelot(); }) .Configure(a => { a.UseOcelot().Wait(); }) .Build(); this.webHost.Start(); } catch (Exception ex) { ServiceEventSource.Current.ServiceWebHostBuilderFailed(ex); } return(Task.FromResult(this.publishAddress)); }
public Task <string> OpenAsync(CancellationToken cancellationToken) { ServiceEventSource.Current.Message("Initialize"); EndpointResourceDescription serviceEndpoint = serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; if (serviceInitializationParameters is StatefulServiceInitializationParameters) { StatefulServiceInitializationParameters statefulInitParams = (StatefulServiceInitializationParameters)serviceInitializationParameters; this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}/{2}/{3}", port, statefulInitParams.PartitionId, statefulInitParams.ReplicaId, Guid.NewGuid()); } else if (serviceInitializationParameters is StatelessServiceInitializationParameters) { this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/'); } else { throw new InvalidOperationException(); } this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); ServiceEventSource.Current.Message("Opening on {0}", this.publishAddress); try { ServiceEventSource.Current.Message("Starting web server on {0}", this.listeningAddress); this.serverHandle = WebApp.Start(this.listeningAddress, appBuilder => this.startup.Configuration(appBuilder)); return(Task.FromResult(this.publishAddress)); } catch (Exception ex) { Trace.WriteLine(ex); this.StopWebServer(); throw; } }
public Task <string> OpenAsync(CancellationToken cancellationToken) { EndpointResourceDescription serviceEndpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint(this.endpointName); int port = serviceEndpoint.Port; if (this.serviceContext is StatefulServiceContext) { StatefulServiceContext statefulServiceContext = this.serviceContext as StatefulServiceContext; this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}{2}/{3}/{4}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/', statefulServiceContext.PartitionId, statefulServiceContext.ReplicaId, Guid.NewGuid()); } else if (this.serviceContext is StatelessServiceContext) { this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/'); } else { throw new InvalidOperationException(); } this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); try { this.eventSource.ServiceMessage(this.serviceContext, "Starting web server on " + this.listeningAddress); this.webApp = WebApp.Start(this.listeningAddress, appBuilder => this.startup.Invoke(appBuilder)); this.eventSource.ServiceMessage(this.serviceContext, "Listening on " + this.publishAddress); return(Task.FromResult(this.publishAddress)); } catch (Exception ex) { this.eventSource.ServiceMessage(this.serviceContext, "Web server failed to open. " + ex.ToString()); this.StopWebServer(); throw; } }
private static string GetListenerUrl(EndpointResourceDescription endpointResourceDescription) { var listenUrl = string.Format( CultureInfo.InvariantCulture, "{0}://+:{1}", endpointResourceDescription.Protocol.ToString().ToLowerInvariant(), endpointResourceDescription.Port); return(listenUrl); }
public FabricOwinCommunicationListener(IApplication appInstance, EndpointResourceDescription endpoint = null) { if (appInstance == null) { throw new ArgumentNullException(nameof(appInstance)); } this.appInstance = appInstance; this.endpoint = endpoint; }
public void Initialize(ServiceInitializationParameters serviceInitializationParameters) { Trace.WriteLine("Initialize"); EndpointResourceDescription serviceEndpoint = serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; string root = String.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + "/"; this.listeningAddress = string.Format("http://+:{0}/{1}", port, root); }
public Task <string> OpenAsync(CancellationToken cancellationToken) { try { // Read settings from the DeviceActorServiceConfig section in the Settings.xml file ICodePackageActivationContext codePackageActivationContext = this.context.CodePackageActivationContext; ConfigurationPackage config = codePackageActivationContext.GetConfigurationPackageObject(ConfigurationPackage); ConfigurationSection section = config.Settings.Sections[ConfigurationSection]; // Check if a parameter called DeviceActorServiceUri exists in the DeviceActorServiceConfig config section if (section.Parameters.Any( p => string.Compare( p.Name, DeviceActorServiceUriParameter, StringComparison.InvariantCultureIgnoreCase) == 0)) { ConfigurationProperty parameter = section.Parameters[DeviceActorServiceUriParameter]; DeviceActorServiceUri = !string.IsNullOrWhiteSpace(parameter?.Value) ? parameter.Value : // By default, the current service assumes that if no URI is explicitly defined for the actor service // in the Setting.xml file, the latter is hosted in the same Service Fabric application. $"fabric:/{this.context.ServiceName.Segments[1]}DeviceActorService"; } else { // By default, the current service assumes that if no URI is explicitly defined for the actor service // in the Setting.xml file, the latter is hosted in the same Service Fabric application. DeviceActorServiceUri = $"fabric:/{this.context.ServiceName.Segments[1]}DeviceActorService"; } EndpointResourceDescription serviceEndpoint = this.context.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; this.listeningAddress = String.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, String.IsNullOrWhiteSpace(this.appRoot) ? String.Empty : this.appRoot.TrimEnd('/') + '/'); this.serverHandle = WebApp.Start(this.listeningAddress, appBuilder => this.startup.Configuration(appBuilder)); string publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); ServiceEventSource.Current.Message($"OWIN listening on [{publishAddress}]"); return(Task.FromResult(publishAddress)); } catch (Exception ex) { ServiceEventSource.Current.Message(ex.Message); throw; } }
public void Initialize(ServiceInitializationParameters serviceInitializationParameters) { ServiceEventSource.Current.Message("Initialize"); EndpointResourceDescription serviceEndpoint = serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; listeningAddress = string.Format("http://+:{0}/", port); publishAddress = listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); }
public void Initialize(ServiceInitializationParameters serviceInitializationParameters) { EndpointResourceDescription serviceEndpoint = serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; this.listeningAddress = String.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, String.IsNullOrWhiteSpace(this.appRoot) ? String.Empty : this.appRoot.TrimEnd('/') + '/'); }
public Task <string> OpenAsync(CancellationToken cancellationToken) { EndpointResourceDescription serviceEndpoint = _serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; _listeningAddress = string.Format("http://+:{0}", port); _serverHandler = WebApp.Start(_listeningAddress, appBuilder => _startup.Configuration(appBuilder)); string resultAddress = _listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); ServiceEventSource.Current.Message("Listening on {0}", resultAddress); return(Task.FromResult(resultAddress)); }
private static EndpointResourceDescription CreateEndpoint(string name, int port) { var endpoint = new EndpointResourceDescription { Name = name }; typeof(EndpointResourceDescription).GetProperty("Port") .GetSetMethod(true) .Invoke(endpoint, new object[] { port }); return(endpoint); }
public Task <string> OpenAsync(CancellationToken cancellationToken) { EndpointResourceDescription endpoint = codePackageActivationContext.GetEndpoint(endpointName); var clusterConfig = nodeContext.ConfigureSeedNodes(akkaConfig, endpoint); var heliosConfig = nodeContext.ConfigureHelios(endpoint); var config = heliosConfig.WithFallback(clusterConfig).WithFallback(akkaConfig); actorSystem = ActorSystem.Create(akkaConfig.GetString(Constants.Akka.SystemName)); return(Task.FromResult(nodeContext.GetSelfAddress(akkaConfig, endpoint))); }
public static string GetEndpoint(this ServiceContext context, string endpointName) { EndpointResourceDescription description = context.CodePackageActivationContext.GetEndpoint(endpointName); string portstr = description.Port == 0 ? "" : $":{description.Port}"; string host = FabricRuntime.GetNodeContext().IPAddressOrFQDN; if (host == "localhost") { host = Loopback; } return ($"net://{host}{portstr}/{description.PathSuffix}"); }
public async Task <string> OpenAsync(CancellationToken cancellationToken) { EndpointResourceDescription endpoint = this.context.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = endpoint.Port; this.listeningAddress = string.Format("http://+:{0}/{1}", port, appRoot); this.publishAddress = this.listeningAddress.Replace( "+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); this.publishAddress = this.publishAddress.Replace("http", "ws"); this.webSocketApp = new WebSocketApp(this.listeningAddress); this.webSocketApp.Init(); this.mainLoop = this.webSocketApp.StartAsync(this.ProcessConnectionAsync); return(await Task.FromResult(this.publishAddress)); }
private static unsafe void ParseEndPoints(NativeRuntime.IFabricCodePackageActivationContext nativeContext, ServiceManifest manifest) { var list = (NativeTypes.FABRIC_ENDPOINT_RESOURCE_DESCRIPTION_LIST *)nativeContext.get_ServiceEndpointResources(); if (list != null) { for (int i = 0; i < list->Count; i++) { IntPtr nativeDescription = list->Items + i * Marshal.SizeOf(typeof(NativeTypes.FABRIC_ENDPOINT_RESOURCE_DESCRIPTION)); manifest.Endpoints.Add(EndpointResourceDescription.CreateFromNative(nativeDescription)); } } }
private static EndpointResourceDescription CreateEndpoint(string name, int port) { var endpoint = new EndpointResourceDescription { Name = name }; typeof(EndpointResourceDescription).GetProperty("Port") .GetSetMethod(true) .Invoke(endpoint, new object[] {port}); return endpoint; }