From 3f6dad872a59794f95a7e6af8b16380572070603 Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Thu, 6 Jun 2024 16:12:54 +0300 Subject: [PATCH] update --- eng/SendToHelix.proj | 111 +++++++++--------- .../App_code/TestDefinitionHelper.cs | 78 +++++++++--- .../tools/SelfHostedCoreWcfService/Program.cs | 2 +- 3 files changed, 119 insertions(+), 72 deletions(-) diff --git a/eng/SendToHelix.proj b/eng/SendToHelix.proj index a0798288c159..3244bf343b48 100644 --- a/eng/SendToHelix.proj +++ b/eng/SendToHelix.proj @@ -24,74 +24,75 @@ - - - - + + + - - - $(XUnitPublishTargetFramework) - - - $(XUnitPublishTargetFramework) - - + + + $(XUnitPublishTargetFramework) + + + $(XUnitPublishTargetFramework) + + - - - - + + + + - - - - - + + + + + - - - - - - - - + + + + + + + + - - - - + + + + - - true - $(BUILD_SOURCEVERSIONAUTHOR) - anon - + + true + $(BUILD_SOURCEVERSIONAUTHOR) + anon + - - - $(HelixPreCommands);dir C:\ /s /b /o:gn | find "SelfHostedCoreWCFService" - $(HelixPreCommands);%HELIX_CORRELATION_PAYLOAD%\SelfHostedCoreWCFService\Release\net6.0\SelfHostedCoreWCFService bootstrap:true - $(HelixPreCommands);%HELIX_CORRELATION_PAYLOAD%\SelfHostedCoreWCFService\$(Configuration)\net6.0\SelfHostedCoreWCFService bootstrap:true - - - - $(HelixPreCommands);find / -type d -name 'SelfHostedCoreWCFService' - $(HelixPreCommands);chmod a+x $HELIX_CORRELATION_PAYLOAD/InstallRootCertificate.sh - $(HelixPreCommands);sudo -E -n $HELIX_CORRELATION_PAYLOAD/InstallRootCertificate.sh --service-host $(ServiceHost) --cert-file /tmp/wcfrootca.crt - $(HelixPreCommands);$HELIX_CORRELATION_PAYLOAD/SelfHostedCoreWCFService/Release/net6.0/SelfHostedCoreWCFService bootstrap:true - $(HelixPreCommands);$HELIX_CORRELATION_PAYLOAD/SelfHostedCoreWCFService/$(Configuration)/net6.0/SelfHostedCoreWCFService bootstrap:true - - + + $(HelixPreCommands);dir C:\ /s /b /o:gn | find "SelfHostedCoreWCFService" + $(HelixPreCommands);%HELIX_CORRELATION_PAYLOAD%\SelfHostedCoreWCFService\Release\net6.0\SelfHostedCoreWCFService bootstrap:true + $(HelixPreCommands);%HELIX_CORRELATION_PAYLOAD%\SelfHostedCoreWCFService\$(Configuration)\net6.0\SelfHostedCoreWCFService bootstrap:true + + + + $(HelixPreCommands);find / -type d -name 'SelfHostedCoreWCFService' + $(HelixPreCommands);chmod a+x $HELIX_CORRELATION_PAYLOAD/InstallRootCertificate.sh + $(HelixPreCommands);sudo -E -n $HELIX_CORRELATION_PAYLOAD/InstallRootCertificate.sh --service-host $(ServiceHost) --cert-file /tmp/wcfrootca.crt + $(HelixPreCommands);$HELIX_CORRELATION_PAYLOAD/SelfHostedCoreWCFService/Release/net6.0/SelfHostedCoreWCFService bootstrap:true + $(HelixPreCommands);$HELIX_CORRELATION_PAYLOAD/SelfHostedCoreWCFService/$(Configuration)/net6.0/SelfHostedCoreWCFService bootstrap:true + + + - + @@ -103,7 +104,7 @@ - SelfHostedCoreWCFService + %(Identity) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestDefinitionHelper.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestDefinitionHelper.cs index 4953315fe91f..91593a89d257 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestDefinitionHelper.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestDefinitionHelper.cs @@ -3,7 +3,10 @@ // See the LICENSE file in the project root for more information. #if NET +using System.Diagnostics; +using System.Net; using System.Security.Claims; +using System.Security.Cryptography.X509Certificates; using CoreWCF.Configuration; using CoreWCF.Description; using idunno.Authentication.Basic; @@ -26,7 +29,7 @@ internal class TestDefinitionHelper private const int DefaultWebSocketPort = 8083; private const int DefaultWebSocketSPort = 8084; - private static IDictionary BaseAddresses + internal static IDictionary BaseAddresses { get { @@ -57,10 +60,47 @@ private static IDictionary BaseAddresses } #if NET + internal class ServiceTestHostOptions + { + public List serviceBaseAddresses = new List(); + public Dictionary endpointBasePath = new Dictionary(); + } + internal static async Task StartHosts() { bool success = true; - var webHost = WebHost.CreateDefaultBuilder() + var serviceTestHostOptionsDict = new Dictionary(); + + var webHost = new WebHostBuilder() + .UseKestrel(options => { + options.Listen(IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.HTTP]).Port); + options.Listen(address: IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.HTTPS]).Port, listenOptions => + { + listenOptions.UseHttps(httpsOptions => + { + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + httpsOptions.ServerCertificate = cert; + }); + if (Debugger.IsAttached) + { + listenOptions.UseConnectionLogging(); + } + }); + options.Listen(IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.WS]).Port); + options.Listen(address: IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.WSS]).Port, listenOptions => + { + listenOptions.UseHttps(httpsOptions => + { + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + httpsOptions.ServerCertificate = cert; + }); + if (Debugger.IsAttached) + { + listenOptions.UseConnectionLogging(); + } + }); + }) + //.UseNetTcp(IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.NETTCP]).Port) .ConfigureServices(services => { services.AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme) @@ -100,8 +140,7 @@ internal static async Task StartHosts() { foreach (var serviceTestHost in GetAttributedServiceHostTypes()) { - var serviceBaseAddresses = new List(); - var endpointBasePath = new Dictionary(); + var serviceTestHostOptions = new ServiceTestHostOptions(); foreach (TestServiceDefinitionAttribute attr in serviceTestHost.GetCustomAttributes(typeof(TestServiceDefinitionAttribute), false)) { Uri serviceBaseAddress = null; @@ -111,9 +150,9 @@ internal static async Task StartHosts() { if (attr.Schema.HasFlag(schema)) { - endpointBasePath.Add(schema, attr.BasePath); + serviceTestHostOptions.endpointBasePath.Add(schema, attr.BasePath); serviceBaseAddress = new Uri(BaseAddresses[(ServiceSchema)schema]); - serviceBaseAddresses.Add(serviceBaseAddress); + serviceTestHostOptions.serviceBaseAddresses.Add(serviceBaseAddress); } } } @@ -132,30 +171,37 @@ internal static async Task StartHosts() } } + serviceTestHostOptionsDict.Add(serviceTestHost.Name, serviceTestHostOptions); try { if (success) { - var serviceHost = (ServiceHost)Activator.CreateInstance(serviceTestHost, serviceBaseAddresses.ToArray()); + string serviceHostTypeName = serviceTestHost.Name; + var serviceHost = (ServiceHost)Activator.CreateInstance(serviceTestHost, serviceTestHostOptionsDict[serviceHostTypeName].serviceBaseAddresses.ToArray()); serviceBuilder.AddService(serviceHost.ServiceType, options => { - foreach (var baseAddress in serviceBaseAddresses) + var localHostTypeName = serviceHostTypeName; + //options.BaseAddresses.Clear(); + foreach (var baseAddress in serviceTestHostOptionsDict[localHostTypeName].serviceBaseAddresses) { if (!options.BaseAddresses.Contains(baseAddress)) options.BaseAddresses.Add(baseAddress); } + + foreach (var endpoint in serviceHost.Endpoints) + { + Enum schema = ServiceHostHelper.ToServiceSchema(endpoint.Binding.Scheme); + string basePath = serviceTestHostOptionsDict[localHostTypeName].endpointBasePath[schema]; + string endpointAddress = string.Format("{0}/{1}", basePath, endpoint.Address); + serviceBuilder.AddServiceEndpoint(serviceHost.ServiceType, endpoint.ContractType, endpoint.Binding, new Uri(endpointAddress, UriKind.RelativeOrAbsolute), null); + } }); - foreach (var endpoint in serviceHost.Endpoints) - { - Enum schema = ServiceHostHelper.ToServiceSchema(endpoint.Binding.Scheme); - string basePath = endpointBasePath[schema]; - string endpointAddress = string.Format("{0}/{1}", basePath, endpoint.Address); - serviceBuilder.AddServiceEndpoint(serviceHost.ServiceType, endpoint.ContractType, endpoint.Binding, new Uri(endpointAddress, UriKind.RelativeOrAbsolute), null); - } + serviceBuilder.ConfigureServiceHostBase(serviceHost.ServiceType, serviceHostBase => { + var localHostTypeName = serviceHostTypeName; var smb = serviceHostBase.Description.Behaviors.Find(); - if (serviceBaseAddresses.Where(uri => uri.Scheme == Uri.UriSchemeHttps).Any()) + if (serviceTestHostOptionsDict[localHostTypeName].serviceBaseAddresses.Where(uri => uri.Scheme == Uri.UriSchemeHttps).Any()) { smb.HttpsGetEnabled = true; } diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Program.cs b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Program.cs index 4f726929c53d..629777d89f91 100644 --- a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Program.cs +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Program.cs @@ -31,7 +31,7 @@ public static async Task Main(string[] args) string crlFileLocation = "c:\\WCFTest\\test.crl"; CertificateGeneratorLibrary.SetupCerts(testserverbase, validatePeriod, crlFileLocation); - + //System.Diagnostics.Debugger.Launch(); Console.WriteLine("Starting services..."); await TestDefinitionHelper.StartHosts();