Service Fabric cluster with 2 exposed https endpoint and different ports -
i created 2 stateless service fabric services, need both exposed , accessible web via https:
- engine, (asp.net core api) exposed via http on port 1212 , https on port 8465
- website (asp.net core web app) exposed via https on port 443
i'm 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 create listeners (like tcp, http) 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 important 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 create listeners (like tcp, http) 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 engine https endpoint removed endpoint , engine.cs
- engine https endpoint never works if website switched http , secure endpoint in solution, browser show "err_connection reset" error.
on servicefabric explorer see both active , running, no errors in output. tried other ports same results.
how can make work?
the error was placing <policies>
in applicationmanifest.xml on top of 2 <servicemanifestimport>
. each service needs different <policy>
inside own<servicemanifestimport>
below <configoverrides />
.
Comments
Post a Comment