Trafeik , Service Fabric Backend , Stateless service, not reachable, always red in explorer - azure-service-fabric

I have deployed trafeik in secured service fabric cluster , and i have made settings in servicemanifest of one of my application to use trafeik, eventhough trafeik is able to identify service but backend in trafeik is always red and my service is unreachable, if i use direct endpoint to my service it is reachable, need help in resolving same.
below is the toml of trafeik -
debug = true
logLevel = "INFO"
defaultEntryPoints = ["https"]
[entryPoints]
[entryPoints.https]
address = ":16080"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "certs/servicefabric.crt"
keyFile = "certs/servicefabric.key"
[entryPoints.traefik]
address = ":16081"
[api]
entryPoint = "traefik"
dashboard = true
debug = true
[servicefabric]
clustermanagementurl = "https://localhost:19080"
apiversion = "3.0"
[serviceFabric.tls]
cert = "certs/servicefabric.crt"
key = "certs/servicefabric.key"
insecureskipverify = true
Service manifest of trafik service -
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="TraefikPkg" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<!-- This is the name of your ServiceType.
The UseImplicitHost attribute indicates this is a guest executable service. -->
<StatelessServiceType ServiceTypeName="TraefikType" UseImplicitHost="true" />
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<!-- The SetupEntryPoint is an optional element used to specify a
program to be executed before the service's code is launched. -->
<EntryPoint>
<ExeHost>
<Program>traefik.exe</Program>
<Arguments>--configfile=traefik.toml</Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
<!-- Uncomment to log console output (both stdout and stderr) to one of the
service's working directories. Do not use in production. -->
<!--<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048" />-->
</ExeHost>
</EntryPoint>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. -->
<Endpoint Protocol="https" Name="TraefikTypeEndpoint" Type="Input" Port="16080" CertificateRef="ClusterThumbprint"/>
<Endpoint Protocol="https" Name="TraefikTypeAPIEndpoint" Type="Input" Port="16081" CertificateRef="ClusterThumbprint"/>
</Endpoints>
</Resources>
</ServiceManifest>
Application manifest of trafeik service -
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest ApplicationTypeName="TraefikType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameters>
<Parameter Name="Traefik_InstanceCount" DefaultValue="-1" />
<Parameter Name="Stateless1_PlacementConstraints" DefaultValue="(NodeTypeName==fntensvcp)" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="TraefikPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<RunAsPolicy CodePackageRef="Code" UserRef="AdminUser" EntryPointType="All" />
</Policies>
</ServiceManifestImport>
<DefaultServices>
<Service Name="Traefik" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="TraefikType" InstanceCount="[Traefik_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
</DefaultServices>
<Principals>
<Users>
<User Name="AdminUser">
<MemberOf>
<SystemGroup Name="Administrators" />
</MemberOf>
</User>
</Users>
</Principals>
<Certificates>
<EndpointCertificate X509FindValue="b22bb9d3e74da3339e5f6709798107443553ae48" Name="ClusterThumbprint" />
</Certificates>
</ApplicationManifest>
For my application below is service manifest -
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="CSM.IE.SMA.C360.RevenueServicePkg" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ManifestId="25bba1ad-7380-4cbf-b9ed-9a90ee3dd086">
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in RegisterServiceType call in Program.cs. -->
<StatelessServiceType ServiceTypeName="CSM.IE.SMA.C360.RevenueServiceType">
<Extensions>
<Extension Name="Traefik">
<Labels xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
<Label Key="traefik.frontend.rule.c360Revenue">PathPrefixStrip: /C360/RevenueService</Label>
<Label Key="traefik.enable">true</Label>
<Label Key="traefik.frontend.passHostHeader">true</Label>
</Labels>
</Extension>
</Extensions>
</StatelessServiceType>
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>CSM.IE.SMA.C360.RevenueService.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. -->
<!--<Endpoint Name="ServiceEndpoint" Protocol="http" Port="8082"/>-->
<Endpoint Protocol="https" Name="ServiceEndpoint" Type="Input" Port="19616" CertificateRef="ClusterThumbprint" />
</Endpoints>
</Resources>
</ServiceManifest>
for my application below is application manifest file -
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="IE_SmartAssistance" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric" ManifestId="1ff9d8a9-ecbc-4d55-931e-eb59eb229f15">
<Parameters>
<Parameter Name="MultiTPIDConsumptionService_InstanceCount" DefaultValue="2" />
<Parameter Name="SupportService_InstanceCount" DefaultValue="2" />
<Parameter Name="ConsumptionService_InstanceCount" DefaultValue="2" />
<Parameter Name="AgreementService_InstanceCount" DefaultValue="2" />
<Parameter Name="RevenueService_InstanceCount" DefaultValue="2" />
<Parameter Name="ProfileProxyService_InstanceCount" DefaultValue="2" />
<Parameter Name="Stateless1_PlacementConstraints" DefaultValue="(NodeTypeName==fntensvcp)" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
ServiceManifest.xml file. -->
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="CSM.IE.SMA.C360.MultiTPIDConsumptionServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy EndpointRef="ServiceEndpoint" CertificateRef="ClusterThumbprint" />
<RunAsPolicy CodePackageRef="Code" UserRef="LocalAdmin" />
</Policies>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="CSM.IE.SMA.C360.AgreementServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy EndpointRef="ServiceEndpoint" CertificateRef="ClusterThumbprint" />
<RunAsPolicy CodePackageRef="Code" UserRef="LocalAdmin" />
</Policies>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="CSM.IE.SMA.C360.RevenueServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy EndpointRef="ServiceEndpoint" CertificateRef="ClusterThumbprint" />
<RunAsPolicy CodePackageRef="Code" UserRef="LocalAdmin" />
</Policies>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="CSM.IE.SMA.C360.ProfileProxyServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy EndpointRef="ServiceEndpoint" CertificateRef="ClusterThumbprint" />
<RunAsPolicy CodePackageRef="Code" UserRef="LocalAdmin" />
</Policies>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="CSM.IE.SMA.C360.ConsumptionServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy EndpointRef="ServiceEndpoint" CertificateRef="ClusterThumbprint" />
<RunAsPolicy CodePackageRef="Code" UserRef="LocalAdmin" />
</Policies>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="CSM.IE.SMA.C360.SupportServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy EndpointRef="ServiceEndpoint" CertificateRef="ClusterThumbprint" />
<RunAsPolicy CodePackageRef="Code" UserRef="LocalAdmin" />
</Policies>
</ServiceManifestImport>
<DefaultServices>
<!-- The section below creates instances of service types, when an instance of this
application type is created. You can also create one or more instances of service type using the
ServiceFabric PowerShell module.
The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. -->
<Service Name="CSM.IE.SMA.C360.MultiTPIDConsumptionService" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="CSM.IE.SMA.C360.MultiTPIDConsumptionServiceType" InstanceCount="[MultiTPIDConsumptionService_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
<Service Name="IE_SmartAssistance_Customer360Service_AgreementService-Microservice_API">
<StatelessService ServiceTypeName="CSM.IE.SMA.C360.AgreementServiceType" InstanceCount="[AgreementService_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
<Service Name="RevenueService-Microservice_API" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="CSM.IE.SMA.C360.RevenueServiceType" InstanceCount="[RevenueService_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
<Service Name="CSM.IE.SMA.C360.ProfileProxyService" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="CSM.IE.SMA.C360.ProfileProxyServiceType" InstanceCount="[ProfileProxyService_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
<Service Name="CSM.IE.SMA.C360.ConsumptionService" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="CSM.IE.SMA.C360.ConsumptionServiceType" InstanceCount="[ConsumptionService_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
<Service Name="CSM.IE.SMA.C360.SupportService" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="CSM.IE.SMA.C360.SupportServiceType" InstanceCount="[SupportService_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
</DefaultServices>
<Principals>
<Users>
<User Name="LocalAdmin" AccountType="NetworkService">
<MemberOf>
<SystemGroup Name="Administrators" />
</MemberOf>
</User>
</Users>
</Principals>
<Certificates>
<EndpointCertificate X509FindValue="b22bb9d3e74da3339e5f6709798107443553ae48" Name="ClusterThumbprint" />
</Certificates>
</ApplicationManifest>

Related

Service Fabric StateLessService only instantiating on one node

I created a brand-new Service Fabric app with a single StatelessService. I expected the service to be instantiated on all five nodes (see my ApplicationManifest.xml file, below), but for some reason it always instantiates on Node 1. Any help in this regard would be greatly appreciated.
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="AlgoistsType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="TradeSafe_ASPNETCORE_ENVIRONMENT" DefaultValue="" />
<Parameter Name="TradeSafe_MinReplicaSetSize" DefaultValue="3" />
<Parameter Name="TradeSafe_PartitionCount" DefaultValue="1" />
<Parameter Name="TradeSafe_TargetReplicaSetSize" DefaultValue="3" />
<Parameter Name="FrontEnd_ASPNETCORE_ENVIRONMENT" DefaultValue="" />
<Parameter Name="FrontEnd_InstanceCount" DefaultValue="-1" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="TradeSafePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<EnvironmentOverrides CodePackageRef="code">
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[TradeSafe_ASPNETCORE_ENVIRONMENT]" />
</EnvironmentOverrides>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="FrontEndPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<EnvironmentOverrides CodePackageRef="code">
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[FrontEnd_ASPNETCORE_ENVIRONMENT]" />
</EnvironmentOverrides>
</ServiceManifestImport>
<DefaultServices>
<Service Name="FrontEnd" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="FrontEndType" InstanceCount="[FrontEnd_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>

Service Fabric Explorer Health State Unknown

The node in my partition keeps switching between Health State = OK and Health State = unknown.
Sometimes the node disappears.
I have tried deleting the service, the app and unprovisioning the type, then redeploying, however I get the same problem.
It is a Service Fabric stateful service, and it's running fine locally, the issue I'm having is only in my dev environment.
I'm using 5 nodes.
ServiceManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="Integration.Optical.ServicePkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in the RegisterServiceAsync call in Program.cs. -->
<StatefulServiceType ServiceTypeName="Integration.Optical.ServiceType" />
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>Integration.Optical.Service.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/>
<EnvironmentVariable Name="KEYVAULT_ENDPOINT" Value=""/>
</EnvironmentVariables>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. -->
<Endpoint Name="ServiceEndpoint" />
<!-- This endpoint is used by the replicator for replicating the state of your service.
This endpoint is configured through a ReplicatorSettings config section in the Settings.xml
file under the ConfigPackage. -->
<Endpoint Name="ReplicatorEndpoint" />
</Endpoints>
</Resources>
</ServiceManifest>
ApplicationManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="Integration.OpticalType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Integration.Optical.Service_ASPNETCORE_ENVIRONMENT" DefaultValue="" />
<Parameter Name="Integration.Optical.Service_KEYVAULT_ENDPOINT" DefaultValue="" />
<Parameter Name="Integration.Optical.Service_MinReplicaSetSize" DefaultValue="3" />
<Parameter Name="Integration.Optical.Service_PartitionCount" DefaultValue="1" />
<Parameter Name="Integration.Optical.Service_TargetReplicaSetSize" DefaultValue="3" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
ServiceManifest.xml file. -->
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Integration.Optical.ServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<EnvironmentOverrides CodePackageRef="code">
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[Integration.Optical.Service_ASPNETCORE_ENVIRONMENT]" />
<EnvironmentVariable Name="KEYVAULT_ENDPOINT" Value="[Integration.Optical.Service_KEYVAULT_ENDPOINT]" />
</EnvironmentOverrides>
</ServiceManifestImport>
<DefaultServices>
<!-- The section below creates instances of service types, when an instance of this
application type is created. You can also create one or more instances of service type using the
ServiceFabric PowerShell module.
The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. -->
<Service Name="Integration.Optical.Service" ServicePackageActivationMode="ExclusiveProcess">
<StatefulService ServiceTypeName="Integration.Optical.ServiceType" TargetReplicaSetSize="[Integration.Optical.Service_TargetReplicaSetSize]" MinReplicaSetSize="[Integration.Optical.Service_MinReplicaSetSize]">
<UniformInt64Partition PartitionCount="[Integration.Optical.Service_PartitionCount]" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
</StatefulService>
</Service>
</DefaultServices>
</ApplicationManifest>
ApplicationParameters/Cloud.xml:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/Integration.Optical" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Integration.Optical.Service_ASPNETCORE_ENVIRONMENT" Value="" />
<Parameter Name="Integration.Optical.Service_KEYVAULT_ENDPOINT" Value="" />
<Parameter Name="Integration.Optical.Service_PartitionCount" Value="1" />
<Parameter Name="Integration.Optical.Service_MinReplicaSetSize" Value="1" />
<Parameter Name="Integration.Optical.Service_TargetReplicaSetSize" Value="1" />
</Parameters>
</Application>
Not sure what part of this fixed it. But this is what I did and it's now working:
In ServiceManifest.xml I added HasPersistedState = true:
<StatefulServiceType ServiceTypeName="Integration.Optical.ServiceType" HasPersistedState="true" />
I moved the app configuration code
ServiceRuntime.RegisterServiceAsync...
from Service.RunAsync() to Program.Main()

Register-ServiceFabricApplicationType : Value cannot be null. Parameter name: source

I'm trying to run my Service Fabric App locally but I'm receiving the follow error:
Register-ServiceFabricApplicationType : Value cannot be null.
Parameter name: source
What is source in this context? And why is it null?
In ApplicationManifest.xml I defined <EnvironmentOverrides> w/ one <EnvironmentVariable> entry but I didn't define that <EnvironmentVariable> in ServiceManifest.xml.
Sample project to illustrate
ApplicationManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="Application1Type" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Web1_InstanceCount" DefaultValue="-1" />
<Parameter Name="OverrideTest" DefaultValue="Do I Get a Useless Error Message?" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Web1Pkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="OverrideTest" Value="[OverrideTest]" />
</EnvironmentOverrides>
</ServiceManifestImport>
....
</DefaultServices>
</ApplicationManifest>
ServiceManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="Web1Pkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="Web1Type" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>Web1.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<!--Uncomment the EnvironmentVariables to get rid of Value cannot be null. >Parameter name: source-->
<!--<EnvironmentVariables>
<EnvironmentVariable Name="OverrideTest" Value="Uncomment-me to get rid of the error" />
</EnvironmentVariables>-->
</CodePackage>
...
</ServiceManifest>

Service Fabric cluster with 2 exposed https endpoint and different ports

I created 2 Stateless Service Fabric services, that I need both exposed and be accessible from the web via https:
Engine, (Asp.net Core API) exposed via HTTP on port 1212 and HTTPS on port 8465
Website (Asp.net Core Web App) exposed via HTTPS on port 443
I'm for now LOCAL ONLY, using WebListener.
ServiceManifest.XML ENGINE
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="EnginePkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="EngineType" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>Engine.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Protocol="http" Name="EngineEndpoint" Type="Input" Port="1212" />
<Endpoint Protocol="https" Name="EngineEndpointSecure" Type="Input" Port="8465" />
</Endpoints>
</Resources>
</ServiceManifest>
ServiceManifest.XML WEBSITE
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="WebsitePkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="WebsiteType" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>Website.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Protocol="https" Name="WebsiteEndpoint" Type="Input" Port="443" />
</Endpoints>
</Resources>
</ServiceManifest>
ENGINE.CS
internal sealed class Engine : StatelessService
{
public Engine(StatelessServiceContext context)
: base(context)
{ }
/// <summary>
/// Optional override to create listeners (like tcp, http) for this service instance.
/// </summary>
/// <returns>The collection of listeners.</returns>
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new WebListenerCommunicationListener(serviceContext, "EngineEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting WebListener on {url}");
return new WebHostBuilder().UseWebListener()
.ConfigureServices(
services => services
.AddSingleton(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseApplicationInsights()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}), "EngineEndpoint"),//Name is important for multiple endpoints
new ServiceInstanceListener(serviceContext =>
new WebListenerCommunicationListener(serviceContext, "EngineEndpointSecure", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Secure WebListener on {url}");
return new WebHostBuilder().UseWebListener()
.ConfigureServices(
services => services
.AddSingleton(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseApplicationInsights()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}), "EngineEndpointSecure")
};
}
}
WEBSITE.CS
internal sealed class Website : StatelessService
{
public Website(StatelessServiceContext context)
: base(context)
{ }
/// <summary>
/// Optional override to create listeners (like tcp, http) for this service instance.
/// </summary>
/// <returns>The collection of listeners.</returns>
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new WebListenerCommunicationListener(serviceContext, "WebsiteEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting WebListener on {url}");
return new WebHostBuilder().UseWebListener()
.ConfigureServices(
services => services
.AddSingleton(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseApplicationInsights()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}), "WebsiteEndpoint"),
};
}
}
APPLICATIONMANIFEST.XML
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="ProjectSFType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<!--STATELESS-->
<Parameter Name="Engine_InstanceCount" DefaultValue="-1" />
<Parameter Name="Website_InstanceCount" DefaultValue="-1" />
</Parameters>
<ServiceManifestImport>
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy EndpointRef="WebsiteEndpoint" CertificateRef="FabricFront" />
<EndpointBindingPolicy EndpointRef="EngineEndpointSecure" CertificateRef="FabricFront" />
</Policies>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="EnginePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="WebsitePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<DefaultServices>
<Service Name="Engine">
<StatelessService ServiceTypeName="EngineType" InstanceCount="[Engine_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
<Service Name="Website">
<StatelessService ServiceTypeName="WebsiteType" InstanceCount="[Website_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
<Certificates>
<EndpointCertificate X509FindValue="‎0000000000000" Name="FabricFront" />
</Certificates>
</ApplicationManifest>
What happens in Local Cluster when launched:
Engine HTTP on port 1212 always works
Website HTTPS endpoint on port 443 works ONLY if the Engine HTTPS endpoint is removed as endpoint and from Engine.cs
Engine HTTPS endpoint NEVER works even if Website is switched to HTTP and is so the only Secure endpoint in the solution, the browser show "ERR_CONNECTION RESET" error.
On ServiceFabric Explorer I see both active and Running, no errors in the Output.
I tried other ports with same results.
How can I make this work?
The error was that I was placing <Policies> in ApplicationManifest.xml on the top of the two <ServiceManifestImport>.
Each Service needs a different <Policy> inside its own<ServiceManifestImport> just below <ConfigOverrides />.
It´s a bit unclear with your question but if you are trying to run one on port 1601 and one on 443 and only 443 succeeds. Then it might be a privilegie problem? Different ports requires different privilegies.
On the other hand if you are trying to bind both on port 443 then it´s likely you get a conflict since they both use the same port and url. We had the same problem and we managed to get past it by doing the following:
Creating a HttpSetup Application that runs a powershell script that
Installs our certificate and registers it using netsh
&netsh http add sslcert hostnameport="${EndpointHost}:${EndpointPort}" certhash=$CertThumbprint certstorename=$CertStore appid=$AppId
Binds the certificates urls, using netsh:
&netsh http add urlacl url=$ReservationUrl"
Example urls
https://mydnsname.com/
https://mydnsname.com/api
In our main application we then bind our services to the full urls since with full urls there is no conflict. We pass the urls to the cluster via environment parameters.
NOTE: The reason we had to split up into two applications was because our main application deployed continously on each commit. And when netsh was run from multiple deployments at the same time it locked up and hanged on the nodes.
ApplicationManifest.xml
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="ApiPkg" ServiceManifestVersion="1.0.0" />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="EndpointUri" Value="[Api_EndpointUri]" />
<EnvironmentVariable Name="CertThumbprint" Value="[Api_CertThumbprint]" />
</EnvironmentOverrides>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="UiPkg" ServiceManifestVersion="1.0.0" />
<EnvironmentOverrides CodePackageRef="Code">
<EnvironmentVariable Name="EndpointUri" Value="[App_EndpointUri]" />
<EnvironmentVariable Name="CertThumbprint" Value="[App_CertThumbprint]" />
</EnvironmentOverrides>
</ServiceManifestImport>
ServiceManifest.xml (for both packages)
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="UiPkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="UiType" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>Ui.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="EndpointUri" Value="" />
<EnvironmentVariable Name="CertThumbprint" Value="" />
</EnvironmentVariables>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<!-- To bind to a specific hostname use netsh from a SetupEntyPoint and change Protocol to tcp here to just open the firewall
-->
<Endpoint Name="ServiceEndpoint" Protocol="tcp" Port="443" />
</Endpoints>
</Resources>
</ServiceManifest>
Program.cs
var listeningAddress = $"{Environment.GetEnvironmentVariable("Api_EndpointUri")}:443/api/";
_webHost = new WebHostBuilder().UseWebListener()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseUrls(listeningAddress)
.Build();

REST Service WebHttpBinding with Http and Https

I have a REST service. This service need to be work with http and https.
I've tried to add two endpoint in my web.config file. But i get this error when i try to browse my service over http:
Could not find a base address that matches scheme https for the
endpoint with binding WebHttpBinding. Registered base address schemes
are [http].
and i get this error when i try to browse over https:
Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].
If i remove one of endpoint from my config file, the both http and https services works fine.
I checked this link: WebHttpBinding with Http and Https
But when i remove endpoints from my config file, the both http and https services runs without any errors on web browser. But when i try to call one of my methods (over a rest client tool) in this service it gets:
500 Internal Server Error.
How can i run this service over http and https without any errors?
My config file is like this:
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" bindingConfiguration="webHttpBinding"/>
<add scheme="https" binding="webHttpBinding" bindingConfiguration="webHttpsBinding"/>
</protocolMapping>
<bindings>
<webHttpBinding>
<binding name="webHttpBinding">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
<binding name="webHttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="MyProject.MyService" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="webHttpBinding" contract="MyProject.IMyService" />
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="webHttpsBinding" contract="MyProject.IMyService" />
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
<!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceAuthorization serviceAuthorizationManagerType="MyProject.RestAuthorizationManager, MyProject"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
here is a sample web.config in order to have both http and https support. i hope solve your problem:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SoapBinding" />
</basicHttpBinding>
<basicHttpsBinding>
<binding name="SecureSoapBinding" />
</basicHttpsBinding>
<webHttpBinding>
<binding name="RestBinding" />
<binding name="SecureRestBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
<mexHttpBinding>
<binding name="MexBinding" />
</mexHttpBinding>
<mexHttpsBinding>
<binding name="SecureMexBinding" />
</mexHttpsBinding>
</bindings>
<client />
<services>
<service behaviorConfiguration="ServiceBehavior" name="Interface.Core">
<endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="SoapBinding" name="Soap" contract="Interface.ICore" />
<endpoint address="soap" binding="basicHttpsBinding" bindingConfiguration="SecureSoapBinding" name="SecureSoap" contract="Interface.ICore" />
<endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="Rest" contract="Interface.ICore" />
<endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="SecureRestBinding" name="SecureRest" contract="Interface.ICore" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="MexBinding" name="Mex" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration="SecureMexBinding" name="SecureMex" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp helpEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>