From 05e132e6c727f0c20579eb46a3a2a14acc544bb3 Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Mon, 1 Apr 2024 07:27:07 +0200 Subject: [PATCH 01/12] Rebase latest code --- NuGet.config | 4 +- System.ServiceModel.sln | 13 +- azure-pipelines-arcade-PR.yml | 5 + azure-pipelines-arcade.yml | 3 + eng/SendToHelix.proj | 60 +- .../Infrastructure/ServiceUtilHelper.cs | 27 +- .../Infrastructure/testproperties.props | 2 +- .../tests/Common/Scenarios/Endpoints.cs | 140 ++--- .../MessageInterceptor/AsyncResult.cs | 236 -------- .../MessageInterceptor/ChainedAsyncResult.cs | 114 ---- .../ChannelMessageInterceptor.cs | 14 - ...MessageInterceptor.IntegrationTests.csproj | 16 - .../InterceptingBindingElement.cs | 72 --- .../InterceptingChannelBase.cs | 94 --- .../InterceptingChannelFactory.cs | 391 ------------- .../InterceptingDuplexChannel.cs | 335 ----------- .../MessageInterceptorTests.4.1.1.cs | 68 --- .../MessageInterceptor/TimeoutHelper.cs | 196 ------- .../CertificateGenerator.sln | 21 +- .../{ => CertificateGenerator}/App.config | 0 .../CertificateGenerator.csproj | 4 +- .../CertificateGenerator/Program.cs | 57 ++ .../CertificateCreationSettings.cs | 0 .../CertificateGenerator.cs | 52 +- .../CertificateGeneratorLibrary.cs | 183 ++++++ .../CertificateGeneratorLibrary.csproj | 11 + .../CertificateHelper.cs | 84 +++ .../CertificateManager.cs | 14 +- .../SafeKeychainHandle.cs | 106 ++++ .../tools/CertificateGenerator/Program.cs | 221 ------- .../App_code/ActivationServiceHostFactory.cs | 2 + .../App_code/AsyncResult.cs | 238 -------- .../BasicServiceAuthorizationManager.cs | 18 +- .../App_code/ChainedAsyncResult.cs | 116 ---- .../App_code/ChannelMessageInterceptor.cs | 21 - .../App_code/ComplexCompositeType.cs | 2 + .../App_code/CompositeType.cs | 4 + .../App_code/CoreWCF/BasicHttpsBinding.cs | 45 ++ .../App_code/CoreWCF/ServiceHostHelper.cs | 92 +++ .../App_code/CoreWCF/TestHostServiceHost.cs | 34 ++ .../App_code/CoreWCF/WcfServiceHost.cs | 58 ++ .../App_code/DataContractResolverService.cs | 4 + .../DigestServiceAuthorizationManager.cs | 16 +- .../App_code/FaultDetail.cs | 2 + .../App_code/FaultDetail2.cs | 2 + .../App_code/FlowControlledStream.cs | 2 + .../App_code/IDataResolverService.cs | 4 + .../App_code/IPushCallback.cs | 4 + .../IISHostedWcfService/App_code/IService1.cs | 4 + .../App_code/ISessionTests.cs | 6 +- .../App_code/IUnderstoodHeaders.cs | 4 + .../App_code/IVerifyWebSockets.cs | 5 + .../App_code/IWSDuplexService.cs | 4 + .../App_code/IWSRequestReplyService.cs | 4 + .../IWcfChannelExtensibilityService.cs | 4 + .../App_code/IWcfCustomUserNameService.cs | 4 + .../App_code/IWcfDecompService.cs | 4 + .../App_code/IWcfDuplexService.cs | 4 + .../App_code/IWcfReliableService.cs | 4 + .../App_code/IWcfRestartService.cs | 4 + .../App_code/IWcfService.4.4.0.cs | 4 + .../App_code/IWcfService.cs | 7 +- .../App_code/IWcfSoapService.cs | 4 + .../App_code/IXmlSFAttribute.cs | 4 + .../App_code/IXmlSerFormatAttrServices.cs | 4 + .../App_code/InterceptingBindingElement.cs | 98 ---- .../InterceptingBindingElementImporter.cs | 19 - .../App_code/InterceptingChannelBase.cs | 96 --- .../App_code/InterceptingChannelFactory.cs | 392 ------------- .../App_code/InterceptingChannelListener.cs | 546 ------------------ .../App_code/InterceptingDuplexChannel.cs | 337 ----------- .../App_code/Interceptingelement.cs | 37 -- .../App_code/KnownTypeA.cs | 2 + .../App_code/MyX509CertificateValidator.cs | 5 + .../App_code/ReplyBankingData.4.4.0.cs | 4 + .../App_code/ReplyBankingData.cs | 4 + .../App_code/ReplyBankingDataNotWrapped.cs | 4 + .../App_code/RequestBankingData.4.4.0.cs | 4 + .../App_code/RequestBankingData.cs | 4 + .../IISHostedWcfService/App_code/Service1.cs | 2 + .../App_code/ServiceActivationsBuilder.cs | 2 + .../ServiceContractAsyncInterfaces.cs | 4 + .../App_code/ServiceContractAsyncServices.cs | 2 + .../App_code/SessionTestsService.cs | 4 + .../App_code/TestDefinitionHelper.cs | 215 ++++++- .../IISHostedWcfService/App_code/TestHost.cs | 36 +- .../TestHttpRequestMessageProperty.cs | 2 + .../TestServiceDefinitionAttribute.cs | 2 + .../App_code/TimeoutHelper.cs | 198 ------- .../App_code/UnderstoodHeaders.cs | 5 + .../App_code/UniqueType.cs | 2 - .../App_code/VerifyWebSockets.cs | 4 + .../App_code/WSDuplexService.cs | 4 + .../App_code/WSRequestReplyService.cs | 7 +- .../WcfChannelExtensibilityService.cs | 48 -- .../App_code/WcfDecompService.cs | 7 +- .../App_code/WcfDuplexService.cs | 4 + .../App_code/WcfReliableService.cs | 4 + .../App_code/WcfRestartService.cs | 34 ++ .../App_code/WcfService.4.4.0.cs | 4 + .../App_code/WcfService.cs | 59 +- .../App_code/WcfSoapService.cs | 4 + .../App_code/WcfWebSocketService.cs | 8 + .../App_code/XmlElementMessageHeader.cs | 5 + .../App_code/XmlSerFormatAttrServices.cs | 7 +- .../App_code/XmlSerializerFormatAttribute.cs | 4 + .../IISHostedWcfService/App_code/mahjong.cs | 4 +- .../testhosts/AuthenticationResourceHelper.cs | 8 + .../testhosts/BasicAuthTestServiceHost.cs | 4 + .../testhosts/BasicHttpService1Host.cs | 5 + .../testhosts/BasicHttpSoapTestServiceHost.cs | 5 + .../BasicHttpTestServiceHost.4.4.0.cs | 5 + .../testhosts/BasicHttpTestServiceHost.cs | 5 + .../BasicHttpXmlSerFormatAttrServiceHost.cs | 5 + ...thMessageCredentialsCertTestServiceHost.cs | 6 + .../testhosts/BasicHttpsTestServiceHost.cs | 5 + ...tyMessageCredentialsCertTestServiceHost.cs | 6 + ...ssageCredentialsUserNameTestServiceHost.cs | 5 + .../ChannelExtensibilityTestServiceHost.cs | 26 - .../CustomTextEncoderBufferedServiceHost.cs | 4 + .../CustomTextEncoderStreamedServiceHost.cs | 5 + .../CustomTextMessageBindingElement.cs | 8 +- .../testhosts/CustomTextMessageEncoder.cs | 13 +- .../CustomTextMessageEncoderFactory.cs | 8 +- .../DataContractResolverTestServiceHost.cs | 10 + .../DefaultCustomHttpTestServiceHost.cs | 4 + .../testhosts/DuplexTestServiceHosts.cs | 22 +- .../AcceptAnyUsernamePasswordValidator.cs | 6 + .../AcceptAnyUsernameSecurityTokenHandler.cs | 6 +- .../BasicAuthenticationBindingElement.cs | 12 +- .../Federation/FederationSTSServiceHost.cs | 10 +- ...nX509SubjectNameOrRSAIssuerNameRegistry.cs | 4 + .../SelfHostSecurityTokenService.cs | 6 +- .../testhosts/HttpBinaryTestServiceHost.cs | 4 + .../HttpDigestNoDomainTestServiceHost.cs | 5 + .../testhosts/HttpSoap11TestServiceHost.cs | 4 + .../HttpSoap11WSA10TestServiceHost.cs | 4 + .../testhosts/HttpSoap11WSA2004ServiceHost.cs | 4 + .../testhosts/HttpSoap12TestServiceHost.cs | 4 + .../testhosts/HttpSoap12WSA2004ServiceHost.cs | 4 + .../HttpSoap12WSANoneTestServiceHost.cs | 4 + .../testhosts/HttpWindowsTestServiceHost.cs | 5 + ...cateValidationChainTrustTestServiceHost.cs | 15 +- ...icateValidationPeerTrustTestServiceHost.cs | 15 +- .../HttpsClientCertificateTestServiceHost.cs | 6 + .../testhosts/HttpsDigestTestServiceHost.cs | 5 + .../testhosts/HttpsNtlmTestServiceHost.cs | 5 + .../testhosts/HttpsSoap11TestServiceHost.cs | 4 + .../testhosts/HttpsSoap12TestServiceHost.cs | 4 + ...tyMessageCredentialsCertTestServiceHost.cs | 6 + ...ssageCredentialsUsernameTestServiceHost.cs | 5 + .../testhosts/HttpsWindowsTestServiceHost.cs | 5 + .../testhosts/NetHttpTestServiceHost.cs | 5 + .../testhosts/NetHttpsTestServiceHost.cs | 5 + .../ReliableSessionDuplexTestServiceHost.cs | 5 + .../ReliableSessionOneWayTestServiceHost.cs | 5 + .../ReliableSessionTestServiceHost.cs | 5 + .../RequestLoggingServiceBehavior.cs | 12 +- .../Saml2IssuedTokenTestServiceHost.cs | 9 +- .../ServiceContractAsyncTestServiceHosts.cs | 5 + ...icateValidationPeerTrustTestServiceHost.cs | 17 +- ...ificateWithServerAltNameTestServiceHost.cs | 17 +- ...tCanonicalNameDomainNameTestServiceHost.cs | 17 +- ...SubjectCanonicalNameFqdnTestServiceHost.cs | 19 +- ...ctCanonicalNameLocalhostTestServiceHost.cs | 17 +- .../TcpDefaultResourceTestServiceHost.cs | 7 +- .../TcpExpiredServerCertTestServiceHost.cs | 17 +- .../TcpInvalidEkuServerCertTestServiceHost.cs | 17 +- .../testhosts/TcpNoSecurityTestServiceHost.cs | 7 +- .../TcpNoSecurityTextTestServiceHost.cs | 6 +- .../TcpRevokedServerCertTestServiceHost.cs | 17 +- .../testhosts/TcpSessionTestServiceHost.cs | 11 +- .../TcpSoap11WSA10TestServiceHost.cs | 6 +- .../TcpStreamedNoSecurityTestServiceHost.cs | 6 +- ...tyMessageCredentialsCertTestServiceHost.cs | 15 +- ...ssageCredentialsUsernameTestServiceHost.cs | 14 +- ...uritySslClientCredentialTypeCertificate.cs | 15 +- ...ySslCustomCertValidationTestServiceHost.cs | 15 +- ...ransportSecurityStreamedTestServiceHost.cs | 6 +- ...TransportSecurityWithSslTestServiceHost.cs | 15 +- .../testhosts/TcpVerifyDNSTestServiceHost.cs | 17 +- .../testhosts/TestHostWebServiceHost.cs | 4 + .../App_code/testhosts/TestServiceHostBase.cs | 11 +- .../testhosts/UnderstoodHeadersServiceHost.cs | 5 + .../testhosts/WSHttpBindingTestServiceHost.cs | 5 + .../testhosts/WcfDecompServiceHost.cs | 5 + .../testhosts/WebSocketTestServiceHosts.cs | 5 + .../XmlSFAttributeTestServiceHost.cs | 5 + ...izerRpcEncWithMessageHeadersServiceHost.cs | 11 +- .../tools/SelfHostedCoreWcfService/Program.cs | 88 +++ .../Properties/launchSettings.json | 11 + .../SelfHostedCoreWCFService.csproj | 82 +++ .../SelfHostedCoreWCFService.sln | 31 + .../appsettings.Development.json | 8 + .../SelfHostedCoreWcfService/appsettings.json | 9 + .../tools/SelfHostedWcfService/Program.cs | 2 +- .../SelfHostedWCFService.csproj | 3 + .../SelfHostedWCFService.sln | 12 +- .../tools/scripts/OpenFirewallPorts.cmd | 2 +- 199 files changed, 2212 insertions(+), 4241 deletions(-) delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/AsyncResult.cs delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/ChainedAsyncResult.cs delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/ChannelMessageInterceptor.cs delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/Extensibility.MessageInterceptor.IntegrationTests.csproj delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingBindingElement.cs delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingChannelBase.cs delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingChannelFactory.cs delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingDuplexChannel.cs delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/MessageInterceptorTests.4.1.1.cs delete mode 100644 src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/TimeoutHelper.cs rename src/System.Private.ServiceModel/tools/CertificateGenerator/{ => CertificateGenerator}/App.config (100%) rename src/System.Private.ServiceModel/tools/CertificateGenerator/{ => CertificateGenerator}/CertificateGenerator.csproj (63%) create mode 100644 src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/Program.cs rename src/System.Private.ServiceModel/tools/CertificateGenerator/{ => CertificateGeneratorLibrary}/CertificateCreationSettings.cs (100%) rename src/System.Private.ServiceModel/tools/CertificateGenerator/{ => CertificateGeneratorLibrary}/CertificateGenerator.cs (92%) create mode 100644 src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.cs create mode 100644 src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.csproj create mode 100644 src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs rename src/System.Private.ServiceModel/tools/CertificateGenerator/{ => CertificateGeneratorLibrary}/CertificateManager.cs (96%) create mode 100644 src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/SafeKeychainHandle.cs delete mode 100644 src/System.Private.ServiceModel/tools/CertificateGenerator/Program.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/AsyncResult.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ChainedAsyncResult.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ChannelMessageInterceptor.cs create mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs create mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/ServiceHostHelper.cs create mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/TestHostServiceHost.cs create mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/WcfServiceHost.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingBindingElement.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingBindingElementImporter.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelBase.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelFactory.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelListener.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingDuplexChannel.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/Interceptingelement.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TimeoutHelper.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfChannelExtensibilityService.cs delete mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ChannelExtensibilityTestServiceHost.cs create mode 100644 src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Program.cs create mode 100644 src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Properties/launchSettings.json create mode 100644 src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj create mode 100644 src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.sln create mode 100644 src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/appsettings.Development.json create mode 100644 src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/appsettings.json diff --git a/NuGet.config b/NuGet.config index d020c02b320..b72212fed1b 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,10 +1,12 @@ - + + + diff --git a/System.ServiceModel.sln b/System.ServiceModel.sln index e6fe89f48f0..f2e998c82cf 100644 --- a/System.ServiceModel.sln +++ b/System.ServiceModel.sln @@ -49,8 +49,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Encoding.MessageVersion.Int EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Extensibility.MessageEncoder.IntegrationTests", "src\System.Private.ServiceModel\tests\Scenarios\Extensibility\MessageEncoder\Extensibility.MessageEncoder.IntegrationTests.csproj", "{76361777-321D-4588-87F9-38992A758350}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Extensibility.MessageInterceptor.IntegrationTests", "src\System.Private.ServiceModel\tests\Scenarios\Extensibility\MessageInterceptor\Extensibility.MessageInterceptor.IntegrationTests.csproj", "{ACCCB1B8-5ABE-4F3B-BFEF-9A9C15AA1267}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Extensibility.WebSockets.IntegrationTests", "src\System.Private.ServiceModel\tests\Scenarios\Extensibility\WebSockets\Extensibility.WebSockets.IntegrationTests.csproj", "{C8CA16D3-5B1E-4EC0-A817-205A798DC272}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure.IntegrationTests", "src\System.Private.ServiceModel\tests\Scenarios\Infrastructure\Infrastructure.IntegrationTests.csproj", "{719E874A-AEFA-44D5-9530-9C41BD0FA4E8}" @@ -91,6 +89,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binding.UDS.IntegrationTest EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.NetNamedPipe.Tests", "src\System.ServiceModel.NetNamedPipe\tests\System.ServiceModel.NetNamedPipe.Tests.csproj", "{FD188537-21AF-48C5-84FF-F8758F4C42A8}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SelfHostedCoreWCFService", "src\System.Private.ServiceModel\tools\SelfHostedCoreWcfService\SelfHostedCoreWCFService.csproj", "{D89D949F-254B-4A29-AE78-DEB081ACA601}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -189,10 +189,6 @@ Global {76361777-321D-4588-87F9-38992A758350}.Debug|Any CPU.Build.0 = Debug|Any CPU {76361777-321D-4588-87F9-38992A758350}.Release|Any CPU.ActiveCfg = Release|Any CPU {76361777-321D-4588-87F9-38992A758350}.Release|Any CPU.Build.0 = Release|Any CPU - {ACCCB1B8-5ABE-4F3B-BFEF-9A9C15AA1267}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ACCCB1B8-5ABE-4F3B-BFEF-9A9C15AA1267}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ACCCB1B8-5ABE-4F3B-BFEF-9A9C15AA1267}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ACCCB1B8-5ABE-4F3B-BFEF-9A9C15AA1267}.Release|Any CPU.Build.0 = Release|Any CPU {C8CA16D3-5B1E-4EC0-A817-205A798DC272}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C8CA16D3-5B1E-4EC0-A817-205A798DC272}.Debug|Any CPU.Build.0 = Debug|Any CPU {C8CA16D3-5B1E-4EC0-A817-205A798DC272}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -265,6 +261,10 @@ Global {FD188537-21AF-48C5-84FF-F8758F4C42A8}.Debug|Any CPU.Build.0 = Debug|Any CPU {FD188537-21AF-48C5-84FF-F8758F4C42A8}.Release|Any CPU.ActiveCfg = Release|Any CPU {FD188537-21AF-48C5-84FF-F8758F4C42A8}.Release|Any CPU.Build.0 = Release|Any CPU + {D89D949F-254B-4A29-AE78-DEB081ACA601}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D89D949F-254B-4A29-AE78-DEB081ACA601}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D89D949F-254B-4A29-AE78-DEB081ACA601}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D89D949F-254B-4A29-AE78-DEB081ACA601}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -289,7 +289,6 @@ Global {48C41A27-631F-45FA-ACD5-7D7EDD4A4931} = {D6302510-AB10-4775-BCE9-98FA96FDEB76} {36DD97F6-1F78-4843-A9C0-58C59D367603} = {D6302510-AB10-4775-BCE9-98FA96FDEB76} {76361777-321D-4588-87F9-38992A758350} = {D6302510-AB10-4775-BCE9-98FA96FDEB76} - {ACCCB1B8-5ABE-4F3B-BFEF-9A9C15AA1267} = {D6302510-AB10-4775-BCE9-98FA96FDEB76} {C8CA16D3-5B1E-4EC0-A817-205A798DC272} = {D6302510-AB10-4775-BCE9-98FA96FDEB76} {719E874A-AEFA-44D5-9530-9C41BD0FA4E8} = {D6302510-AB10-4775-BCE9-98FA96FDEB76} {E878E412-F0AB-4D87-8A7A-3114AAC48CD5} = {D6302510-AB10-4775-BCE9-98FA96FDEB76} diff --git a/azure-pipelines-arcade-PR.yml b/azure-pipelines-arcade-PR.yml index 9ef33785dba..f862d72e6ea 100644 --- a/azure-pipelines-arcade-PR.yml +++ b/azure-pipelines-arcade-PR.yml @@ -31,6 +31,8 @@ variables: value: true - name: _RunAsInternal value: false + - name: _RunWithCoreWcfService + value: true - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - name: _RunAsPublic @@ -134,6 +136,7 @@ stages: XUnitWorkItemTimeout: $(_xUnitWorkItemTimeout) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) + RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: true # Only build and test Linux in PR and CI builds. @@ -194,6 +197,7 @@ stages: ServiceHost: $(_serviceUri) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) + RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: false # Only build and test MacOS in PR and CI builds. @@ -253,4 +257,5 @@ stages: ServiceHost: $(_serviceUri) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) + RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: false \ No newline at end of file diff --git a/azure-pipelines-arcade.yml b/azure-pipelines-arcade.yml index dc42bf058bf..590ccd4cdda 100644 --- a/azure-pipelines-arcade.yml +++ b/azure-pipelines-arcade.yml @@ -24,6 +24,8 @@ variables: value: false - name: _RunAsInternal value: true +- name: _RunWithCoreWcfService + value: true - group: DotNet-Wcf-SDLValidation-Params resources: repositories: @@ -98,6 +100,7 @@ extends: XUnitWorkItemTimeout: $(_xUnitWorkItemTimeout) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) + RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: true - ${{ if eq(variables._RunAsInternal, True) }}: - template: /eng/common/templates-official/post-build/post-build.yml@self diff --git a/eng/SendToHelix.proj b/eng/SendToHelix.proj index 6a3f8e481bf..78ad194a2d6 100644 --- a/eng/SendToHelix.proj +++ b/eng/SendToHelix.proj @@ -1,20 +1,35 @@ - + pr/dotnet/wcf/$(BUILD_SOURCEBRANCH)/ official/dotnet/wcf/$(BUILD_SOURCEBRANCH)/ test/product/ $(BUILD_BUILDNUMBER) 123460.01 - sdk - 8.0.100 - true + + $([System.IO.File]::ReadAllText('$(RepoRoot)global.json')) + sdk + $([System.Text.RegularExpressions.Regex]::Match($(GlobalJsonContent), '(%3F<="dotnet": ").*(%3F=")')) + + true true $(AGENT_JOBNAME) - true + + + + aspnetcore-runtime + Current + + + + + + + + $(XUnitPublishTargetFramework) @@ -54,19 +69,48 @@ $(BUILD_SOURCEVERSIONAUTHOR) anon - - + + + false + + + $(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);set PATH=%HELIX_CORRELATION_PAYLOAD%\dotnet-cli%3B%PATH% + + $(HelixPreCommands);set DOTNET_ROOT=%HELIX_CORRELATION_PAYLOAD%\dotnet-cli;set DOTNET_CLI_TELEMETRY_OPTOUT=1 + $(HelixPreCommands);set DOTNET_CLI_HOME=%HELIX_WORKITEM_ROOT%\.dotnet + $(HelixPreCommands);set NUGET_PACKAGES=%HELIX_WORKITEM_ROOT%\.nuget + $(HelixPreCommands);set ServiceUri=localhost + $(HelixPreCommands);%HELIX_CORRELATION_PAYLOAD%\SelfHostedCoreWCFService\$(Configuration)\net8.0\SelfHostedCoreWCFService bootstrap:true + + + + $(HelixPreCommands);export PATH=$HELIX_CORRELATION_PAYLOAD/dotnet-cli:$PATH + $(HelixPreCommands);export DOTNET_ROOT=$HELIX_CORRELATION_PAYLOAD/dotnet-cli;export DOTNET_CLI_TELEMETRY_OPTOUT=1 + $(HelixPreCommands);export DOTNET_CLI_HOME=$HELIX_WORKITEM_ROOT/.dotnet + $(HelixPreCommands);export NUGET_PACKAGES=$HELIX_WORKITEM_ROOT/.nuget + $(HelixPreCommands);export ServiceUri=localhost + $(HelixPreCommands);dotnet exec --roll-forward Major $HELIX_CORRELATION_PAYLOAD/SelfHostedCoreWCFService/$(Configuration)/net8.0/SelfHostedCoreWCFService.dll bootstrap:true + + + + + %(Identity) + + + SelfHostedCoreWCFService + diff --git a/src/System.Private.ServiceModel/tests/Common/Infrastructure/ServiceUtilHelper.cs b/src/System.Private.ServiceModel/tests/Common/Infrastructure/ServiceUtilHelper.cs index 374dcaf34e8..f6b4edb7e9d 100644 --- a/src/System.Private.ServiceModel/tests/Common/Infrastructure/ServiceUtilHelper.cs +++ b/src/System.Private.ServiceModel/tests/Common/Infrastructure/ServiceUtilHelper.cs @@ -535,7 +535,14 @@ public static string GetResourceFromServiceAsString(string resource) using (HttpClient httpClient = new HttpClient()) { HttpResponseMessage response = httpClient.GetAsync(requestUri).GetAwaiter().GetResult(); - return response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + if (response.IsSuccessStatusCode) + { + return response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + } + else + { + throw new Exception($"Got Status code {response.StatusCode} from {requestUri}."); + } } } @@ -547,7 +554,14 @@ public static byte[] GetResourceFromServiceAsByteArray(string resource) using (HttpClient httpClient = new HttpClient()) { HttpResponseMessage response = httpClient.GetAsync(requestUri).GetAwaiter().GetResult(); - return response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); + if (response.IsSuccessStatusCode) + { + return response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); + } + else + { + throw new Exception($"Got Status code {response.StatusCode} from {requestUri}."); + } } } @@ -559,7 +573,14 @@ public static async Task GetResourceFromServiceAsByteArrayAsync(string r using (HttpClient httpClient = new HttpClient()) { HttpResponseMessage response = await httpClient.GetAsync(requestUri); - return await response.Content.ReadAsByteArrayAsync(); + if (response.IsSuccessStatusCode) + { + return await response.Content.ReadAsByteArrayAsync(); + } + else + { + throw new Exception($"Got Status code {response.StatusCode} from {requestUri}."); + } } } } diff --git a/src/System.Private.ServiceModel/tests/Common/Infrastructure/testproperties.props b/src/System.Private.ServiceModel/tests/Common/Infrastructure/testproperties.props index 0fad0893561..224645a2bd3 100644 --- a/src/System.Private.ServiceModel/tests/Common/Infrastructure/testproperties.props +++ b/src/System.Private.ServiceModel/tests/Common/Infrastructure/testproperties.props @@ -19,7 +19,7 @@ - 809 + 8808 diff --git a/src/System.Private.ServiceModel/tests/Common/Scenarios/Endpoints.cs b/src/System.Private.ServiceModel/tests/Common/Scenarios/Endpoints.cs index 6b35509a7ba..4ce75d83cbf 100644 --- a/src/System.Private.ServiceModel/tests/Common/Scenarios/Endpoints.cs +++ b/src/System.Private.ServiceModel/tests/Common/Scenarios/Endpoints.cs @@ -20,7 +20,7 @@ private static string GetEndpointAddress(string endpoint, string protocol = "htt // HTTP Addresses public static string DefaultCustomHttp_Address { - get { return GetEndpointAddress("DefaultCustomHttp.svc//default-custom-http"); } + get { return GetEndpointAddress("DefaultCustomHttp.svc/default-custom-http"); } } public static string HttpBaseAddress_Basic_Text @@ -40,18 +40,18 @@ public static string HttpBaseAddress_BasicDecomp public static string HttpBaseAddress_BasicService1 { - get { return GetEndpointAddress("BasicService1.svc//Service1"); } + get { return GetEndpointAddress("BasicService1.svc/Service1"); } } // Endpoint that relies on post-1.1.0 features public static string HttpBaseAddress_4_4_0_Basic { - get { return GetEndpointAddress("BasicHttp_4_4_0.svc//Basic"); } + get { return GetEndpointAddress("BasicHttp_4_4_0.svc/Basic"); } } public static string HttpBaseAddress_Basic_Soap { - get { return GetEndpointAddress("BasicHttpSoap.svc//Basic"); } + get { return GetEndpointAddress("BasicHttpSoap.svc/Basic"); } } public static string HttpBaseAddress_NetHttp @@ -61,37 +61,37 @@ public static string HttpBaseAddress_NetHttp public static string HttpSoap11_Address { - get { return GetEndpointAddress("HttpSoap11.svc//http-soap11"); } + get { return GetEndpointAddress("HttpSoap11.svc/http-soap11"); } } public static string HttpSoap11WSA10_Address { - get { return GetEndpointAddress("HttpSoap11WSA10.svc//http-Soap11WSA10"); } + get { return GetEndpointAddress("HttpSoap11WSA10.svc/http-Soap11WSA10"); } } public static string HttpSoap11WSA2004_Address { - get { return GetEndpointAddress("HttpSoap11WSA2004.svc//http-Soap11WSA2004"); } + get { return GetEndpointAddress("HttpSoap11WSA2004.svc/http-Soap11WSA2004"); } } public static string HttpSoap12_Address { - get { return GetEndpointAddress("HttpSoap12.svc//http-soap12"); } + get { return GetEndpointAddress("HttpSoap12.svc/http-soap12"); } } public static string HttpSoap12WSANone_Address { - get { return GetEndpointAddress("HttpSoap12WSANone.svc//http-Soap12WSANone"); } + get { return GetEndpointAddress("HttpSoap12WSANone.svc/http-Soap12WSANone"); } } public static string HttpSoap12WSA2004_Address { - get { return GetEndpointAddress("HttpSoap12WSA2004.svc//http-Soap12WSA2004"); } + get { return GetEndpointAddress("HttpSoap12WSA2004.svc/http-Soap12WSA2004"); } } public static string HttpBinary_Address { - get { return GetEndpointAddress("HttpBinary.svc//http-binary"); } + get { return GetEndpointAddress("HttpBinary.svc/http-binary"); } } public static string HttpProtocolError_Address @@ -101,52 +101,52 @@ public static string HttpProtocolError_Address public static string HttpBaseAddress_ChannelExtensibility { - get { return GetEndpointAddress("ChannelExtensibility.svc//ChannelExtensibility"); } + get { return GetEndpointAddress("ChannelExtensibility.svc/ChannelExtensibility"); } } public static string UnderstoodHeaders { - get { return GetEndpointAddress("UnderstoodHeaders.svc//UnderstoodHeaders"); } + get { return GetEndpointAddress("UnderstoodHeaders.svc/UnderstoodHeaders"); } } public static string XmlSFAttribute_Address { - get { return GetEndpointAddress("XmlSFAttribute.svc//XmlSFAttribute"); } + get { return GetEndpointAddress("XmlSFAttribute.svc/XmlSFAttribute"); } } public static string BasicHttpRpcEncSingleNs_Address { - get { return GetEndpointAddress("BasicHttpRpcEncSingleNs.svc//Basic"); } + get { return GetEndpointAddress("BasicHttpRpcEncSingleNs.svc/Basic"); } } public static string BasicHttpRpcLitSingleNs_Address { - get { return GetEndpointAddress("BasicHttpRpcLitSingleNs.svc//Basic"); } + get { return GetEndpointAddress("BasicHttpRpcLitSingleNs.svc/Basic"); } } public static string BasicHttpDocLitSingleNs_Address { - get { return GetEndpointAddress("BasicHttpDocLitSingleNs.svc//Basic"); } + get { return GetEndpointAddress("BasicHttpDocLitSingleNs.svc/Basic"); } } public static string BasicHttpRpcEncDualNs_Address { - get { return GetEndpointAddress("BasicHttpRpcEncDualNs.svc//Basic"); } + get { return GetEndpointAddress("BasicHttpRpcEncDualNs.svc/Basic"); } } public static string BasicHttpRpcLitDualNs_Address { - get { return GetEndpointAddress("BasicHttpRpcLitDualNs.svc//Basic"); } + get { return GetEndpointAddress("BasicHttpRpcLitDualNs.svc/Basic"); } } public static string BasicHttpDocLitDualNs_Address { - get { return GetEndpointAddress("BasicHttpDocLitDualNs.svc//Basic"); } + get { return GetEndpointAddress("BasicHttpDocLitDualNs.svc/Basic"); } } public static string BasicHttpRpcEncWithHeaders_Address { - get { return GetEndpointAddress("BasicHttpRpcEncWithHeaders.svc//Basic"); } + get { return GetEndpointAddress("BasicHttpRpcEncWithHeaders.svc/Basic"); } } public static string ReliableSession_NetHttp @@ -177,22 +177,22 @@ public static string WSHttpBindingBaseAddress #region WebSocket Addresses public static string HttpBaseAddress_NetHttpWebSockets { - get { return GetEndpointAddress("NetHttpWebSockets.svc//NetHttpWebSockets", "ws"); } + get { return GetEndpointAddress("NetHttpWebSockets.svc/NetHttpWebSockets", "ws"); } } public static string HttpBaseAddress_NetHttpsWebSockets { - get { return GetEndpointAddress("NetHttpsWebSockets.svc//NetHttpsWebSockets", protocol: "wss"); } + get { return GetEndpointAddress("NetHttpsWebSockets.svc/NetHttpsWebSockets", protocol: "wss"); } } public static string NetHttpWebSocketTransport_Address { - get { return GetEndpointAddress("WebSocketTransport.svc//http-requestreplywebsockets-transportusagealways", protocol: "ws"); } + get { return GetEndpointAddress("WebSocketTransport.svc/http-requestreplywebsockets-transportusagealways", protocol: "ws"); } } public static string NetHttpDuplexWebSocket_Address { - get { return GetEndpointAddress("DuplexWebSocket.svc//http-defaultduplexwebsockets", protocol: "ws"); } + get { return GetEndpointAddress("DuplexWebSocket.svc/http-defaultduplexwebsockets", protocol: "ws"); } } public static string WebSocketHttpDuplexStreamed_Address @@ -217,44 +217,44 @@ public static string WebSocketHttpDuplexBuffered_Address public static string WebSocketHttpVerifyWebSocketsUsed_Address { - get { return GetEndpointAddress("WebSocketHttpVerifyWebSocketsUsed.svc//WebSocketHttpVerifyWebSocketsUsed", protocol: "ws"); } + get { return GetEndpointAddress("WebSocketHttpVerifyWebSocketsUsed.svc/WebSocketHttpVerifyWebSocketsUsed", protocol: "ws"); } } #endregion WebSocket Addresses #region Service Contract Addresses public static string ServiceContractAsyncIntOut_Address { - get { return GetEndpointAddress("ServiceContractAsyncIntOut.svc//ServiceContractIntOut"); } + get { return GetEndpointAddress("ServiceContractAsyncIntOut.svc/ServiceContractIntOut"); } } public static string ServiceContractAsyncUniqueTypeOut_Address { - get { return GetEndpointAddress("ServiceContractAsyncUniqueTypeOut.svc//ServiceContractUniqueTypeOut"); } + get { return GetEndpointAddress("ServiceContractAsyncUniqueTypeOut.svc/ServiceContractUniqueTypeOut"); } } public static string ServiceContractAsyncIntRef_Address { - get { return GetEndpointAddress("ServiceContractAsyncIntRef.svc//ServiceContractIntRef"); } + get { return GetEndpointAddress("ServiceContractAsyncIntRef.svc/ServiceContractIntRef"); } } public static string ServiceContractAsyncUniqueTypeRef_Address { - get { return GetEndpointAddress("ServiceContractAsyncUniqueTypeRef.svc//ServiceContractAsyncUniqueTypeRef"); } + get { return GetEndpointAddress("ServiceContractAsyncUniqueTypeRef.svc/ServiceContractAsyncUniqueTypeRef"); } } public static string ServiceContractSyncUniqueTypeOut_Address { - get { return GetEndpointAddress("ServiceContractSyncUniqueTypeOut.svc//ServiceContractUniqueTypeOutSync"); } + get { return GetEndpointAddress("ServiceContractSyncUniqueTypeOut.svc/ServiceContractUniqueTypeOutSync"); } } public static string ServiceContractSyncUniqueTypeRef_Address { - get { return GetEndpointAddress("ServiceContractSyncUniqueTypeRef.svc//ServiceContractUniqueTypeRefSync"); } + get { return GetEndpointAddress("ServiceContractSyncUniqueTypeRef.svc/ServiceContractUniqueTypeRefSync"); } } public static string DataContractResolver_Address { - get { return GetEndpointAddress("DataContractResolver.svc//DataContractResolver"); } + get { return GetEndpointAddress("DataContractResolver.svc/DataContractResolver"); } } #endregion Service Contract Addresses @@ -263,12 +263,12 @@ public static string DataContractResolver_Address public static string CustomTextEncoderBuffered_Address { - get { return GetEndpointAddress("CustomTextEncoderBuffered.svc//http-customtextencoder"); } + get { return GetEndpointAddress("CustomTextEncoderBuffered.svc/http-customtextencoder"); } } public static string CustomTextEncoderStreamed_Address { - get { return GetEndpointAddress("CustomTextEncoderStreamed.svc//http-customtextencoder-streamed"); } + get { return GetEndpointAddress("CustomTextEncoderStreamed.svc/http-customtextencoder-streamed"); } } #endregion Custom Message Encoder Addresses #endregion HTTP Addresses @@ -303,7 +303,7 @@ public static string Https_NtlmAuth_Address { get { - return GetEndpointAddress("WindowAuthenticationNtlm/HttpsNtlm.svc//https-ntlm", protocol: "https"); + return GetEndpointAddress("WindowAuthenticationNtlm/HttpsNtlm.svc/https-ntlm", protocol: "https"); } } @@ -351,7 +351,7 @@ public static string HttpsSoap11_Address { get { - return GetEndpointAddress("HttpsSoap11.svc//https-soap11", protocol: "https"); + return GetEndpointAddress("HttpsSoap11.svc/https-soap11", protocol: "https"); } } @@ -359,7 +359,7 @@ public static string HttpsSoap12_Address { get { - return GetEndpointAddress("HttpsSoap12.svc//https-soap12", protocol: "https"); + return GetEndpointAddress("HttpsSoap12.svc/https-soap12", protocol: "https"); } } @@ -383,7 +383,7 @@ public static string Https_SecModeTrans_ClientCredTypeNone_ServerCertValModePeer { get { - return GetEndpointAddress("HttpsCertValModePeerTrust.svc//https-server-cert-valmode-peertrust", protocol: "https"); + return GetEndpointAddress("HttpsCertValModePeerTrust.svc/https-server-cert-valmode-peertrust", protocol: "https"); } } @@ -391,7 +391,7 @@ public static string Https_SecModeTrans_ClientCredTypeNone_ServerCertValModeChai { get { - return GetEndpointAddress("HttpsCertValModeChainTrust.svc//https-server-cert-valmode-chaintrust", protocol: "https"); + return GetEndpointAddress("HttpsCertValModeChainTrust.svc/https-server-cert-valmode-chaintrust", protocol: "https"); } } @@ -399,7 +399,7 @@ public static string Https_SecModeTransWithMessCred_ClientCredTypeCert { get { - return GetEndpointAddress("HttpsTransSecMessCredsCert.svc//https-message-credentials-cert", protocol: "https"); + return GetEndpointAddress("HttpsTransSecMessCredsCert.svc/https-message-credentials-cert", protocol: "https"); } } @@ -407,7 +407,7 @@ public static string Https_SecModeTransWithMessCred_ClientCredTypeUserName { get { - return GetEndpointAddress("HttpsTransSecMessCredsUserName.svc//https-message-credentials-username", protocol: "https"); + return GetEndpointAddress("HttpsTransSecMessCredsUserName.svc/https-message-credentials-username", protocol: "https"); } } @@ -415,7 +415,7 @@ public static string Https2007_SecModeTransWithMessCred_ClientCredTypeCert { get { - return GetEndpointAddress("HttpsTransSecMessCredsCert.svc//https2007-message-credentials-cert", protocol: "https"); + return GetEndpointAddress("HttpsTransSecMessCredsCert.svc/https2007-message-credentials-cert", protocol: "https"); } } @@ -423,7 +423,7 @@ public static string Https2007_SecModeTransWithMessCred_ClientCredTypeUserName { get { - return GetEndpointAddress("HttpsTransSecMessCredsUserName.svc//https2007-message-credentials-username", protocol: "https"); + return GetEndpointAddress("HttpsTransSecMessCredsUserName.svc/https2007-message-credentials-username", protocol: "https"); } } @@ -431,7 +431,7 @@ public static string BasicHttps_SecModeTransWithMessCred_ClientCredTypeCert { get { - return GetEndpointAddress("BasicHttpsTransSecMessCredsCert.svc//https-message-credentials-cert", protocol: "https"); + return GetEndpointAddress("BasicHttpsTransSecMessCredsCert.svc/https-message-credentials-cert", protocol: "https"); } } @@ -439,7 +439,7 @@ public static string BasicHttpsBinding_SecModeTransWithMessCred_ClientCredTypeCe { get { - return GetEndpointAddress("BasicHttpsBindingTransSecMessCredsCert.svc//https-transwithmessage-credentials-cert", protocol: "https"); + return GetEndpointAddress("BasicHttpsBindingTransSecMessCredsCert.svc/https-transwithmessage-credentials-cert", protocol: "https"); } } @@ -447,7 +447,7 @@ public static string BasicHttps_SecModeTransWithMessCred_ClientCredTypeUserName { get { - return GetEndpointAddress("BasicHttpsTransSecMessCredsUserName.svc//https-message-credentials-username", protocol: "https"); + return GetEndpointAddress("BasicHttpsTransSecMessCredsUserName.svc/https-message-credentials-username", protocol: "https"); } } @@ -506,24 +506,24 @@ public static string WebSocketHttpsDuplexBuffered_Address // net.tcp Addresses public static string Tcp_DefaultBinding_Address { - get { return GetEndpointAddress("TcpDefault.svc//tcp-default", protocol: "net.tcp"); } + get { return GetEndpointAddress("TcpDefault.svc/tcp-default", protocol: "net.tcp"); } } public static string Tcp_NoSecurity_Address { - get { return GetEndpointAddress("TcpNoSecurity.svc//tcp-nosecurity", protocol: "net.tcp"); } + get { return GetEndpointAddress("TcpNoSecurity.svc/tcp-nosecurity", protocol: "net.tcp"); } } public static string Tcp_Streamed_NoSecurity_Address { - get { return GetEndpointAddress("TcpStreamedNoSecurity.svc//tcp-streamed-nosecurity", protocol: "net.tcp"); } + get { return GetEndpointAddress("TcpStreamedNoSecurity.svc/tcp-streamed-nosecurity", protocol: "net.tcp"); } } public static string Tcp_VerifyDNS_Address { get { - return GetEndpointAddress("TcpVerifyDNS.svc//tcp-VerifyDNS", protocol: "net.tcp"); + return GetEndpointAddress("TcpVerifyDNS.svc/tcp-VerifyDNS", protocol: "net.tcp"); } } @@ -539,7 +539,7 @@ public static string Tcp_ExpiredServerCertResource_Address { get { - return GetEndpointAddress("TcpExpiredServerCert.svc//tcp-ExpiredServerCert", protocol: "net.tcp"); + return GetEndpointAddress("TcpExpiredServerCert.svc/tcp-ExpiredServerCert", protocol: "net.tcp"); } } @@ -555,7 +555,7 @@ public static string Tcp_InvalidEkuServerCertResource_Address { get { - return GetEndpointAddress("TcpInvalidEkuServerCert.svc//tcp-InvalidEkuServerCert", protocol: "net.tcp"); + return GetEndpointAddress("TcpInvalidEkuServerCert.svc/tcp-InvalidEkuServerCert", protocol: "net.tcp"); } } @@ -571,7 +571,7 @@ public static string Tcp_RevokedServerCertResource_Address { get { - return GetEndpointAddress("TcpRevokedServerCert.svc//tcp-RevokedServerCert", protocol: "net.tcp"); + return GetEndpointAddress("TcpRevokedServerCert.svc/tcp-RevokedServerCert", protocol: "net.tcp"); } } @@ -586,32 +586,32 @@ public static string Tcp_ExpiredServerCertResource_HostName public static string Tcp_NoSecurity_Callback_Address { - get { return GetEndpointAddress("Duplex.svc//tcp-nosecurity-callback", protocol: "net.tcp"); } + get { return GetEndpointAddress("Duplex.svc/tcp-nosecurity-callback", protocol: "net.tcp"); } } public static string Tcp_CustomBinding_NoSecurity_Text_Address { - get { return GetEndpointAddress("TcpNoSecurityText.svc//tcp-custombinding-nosecurity-text", protocol: "net.tcp"); } + get { return GetEndpointAddress("TcpNoSecurityText.svc/tcp-custombinding-nosecurity-text", protocol: "net.tcp"); } } public static string Tcp_NoSecurity_TaskReturn_Address { - get { return GetEndpointAddress("DuplexChannelCallbackReturn.svc//tcp-nosecurity-taskreturn", protocol: "net.tcp"); } + get { return GetEndpointAddress("DuplexChannelCallbackReturn.svc/tcp-nosecurity-taskreturn", protocol: "net.tcp"); } } public static string Tcp_NoSecurity_DuplexCallback_Address { - get { return GetEndpointAddress("DuplexCallback.svc//tcp-nosecurity-typedproxy-duplexcallback", protocol: "net.tcp"); } + get { return GetEndpointAddress("DuplexCallback.svc/tcp-nosecurity-typedproxy-duplexcallback", protocol: "net.tcp"); } } public static string Tcp_NoSecurity_DataContractDuplexCallback_Address { - get { return GetEndpointAddress("DuplexCallbackDataContractComplexType.svc//tcp-nosecurity-callback", protocol: "net.tcp"); } + get { return GetEndpointAddress("DuplexCallbackDataContractComplexType.svc/tcp-nosecurity-callback", protocol: "net.tcp"); } } public static string Tcp_NoSecurity_XmlDuplexCallback_Address { - get { return GetEndpointAddress("DuplexCallbackXmlComplexType.svc//tcp-nosecurity-callback", protocol: "net.tcp"); } + get { return GetEndpointAddress("DuplexCallbackXmlComplexType.svc/tcp-nosecurity-callback", protocol: "net.tcp"); } } @@ -619,7 +619,7 @@ public static string Tcp_CustomBinding_SslStreamSecurity_Address { get { - return GetEndpointAddress("TcpTransportSecurityWithSsl.svc//tcp-server-ssl-security", protocol: "net.tcp"); + return GetEndpointAddress("TcpTransportSecurityWithSsl.svc/tcp-server-ssl-security", protocol: "net.tcp"); } } @@ -635,7 +635,7 @@ public static string Tcp_ClientCredentialType_Certificate_Address { get { - return GetEndpointAddress("TcpTransportSecuritySslClientCredentialTypeCertificate.svc//tcp-server-ssl-security-clientcredentialtype-certificate", protocol: "net.tcp"); + return GetEndpointAddress("TcpTransportSecuritySslClientCredentialTypeCertificate.svc/tcp-server-ssl-security-clientcredentialtype-certificate", protocol: "net.tcp"); } } @@ -643,7 +643,7 @@ public static string Tcp_ClientCredentialType_Certificate_CustomValidation_Addre { get { - return GetEndpointAddress("TcpTransportSecuritySslCustomCertValidation.svc//tcp-server-ssl-security-clientcredentialtype-certificate-customvalidator", protocol: "net.tcp"); + return GetEndpointAddress("TcpTransportSecuritySslCustomCertValidation.svc/tcp-server-ssl-security-clientcredentialtype-certificate-customvalidator", protocol: "net.tcp"); } } @@ -651,7 +651,7 @@ public static string Tcp_ClientCredentialType_Certificate_With_ServerAltName_Add { get { - return GetEndpointAddress("TcpCertificateWithServerAltName.svc//tcp-server-alt-name-cert", protocol: "net.tcp"); + return GetEndpointAddress("TcpCertificateWithServerAltName.svc/tcp-server-alt-name-cert", protocol: "net.tcp"); } } @@ -659,7 +659,7 @@ public static string Tcp_ClientCredentialType_Certificate_With_CanonicalName_Loc { get { - return GetEndpointAddress("TcpCertificateWithSubjectCanonicalNameLocalhost.svc//tcp-server-subject-cn-localhost-cert", protocol: "net.tcp"); + return GetEndpointAddress("TcpCertificateWithSubjectCanonicalNameLocalhost.svc/tcp-server-subject-cn-localhost-cert", protocol: "net.tcp"); } } @@ -667,7 +667,7 @@ public static string Tcp_ClientCredentialType_Certificate_With_CanonicalName_Dom { get { - return GetEndpointAddress("TcpCertificateWithSubjectCanonicalNameDomainName.svc//tcp-server-subject-cn-domainname-cert", protocol: "net.tcp"); + return GetEndpointAddress("TcpCertificateWithSubjectCanonicalNameDomainName.svc/tcp-server-subject-cn-domainname-cert", protocol: "net.tcp"); } } @@ -675,7 +675,7 @@ public static string Tcp_ClientCredentialType_Certificate_With_CanonicalName_Fqd { get { - return GetEndpointAddress("TcpCertificateWithSubjectCanonicalNameFqdn.svc//tcp-server-subject-cn-fqdn-cert", protocol: "net.tcp"); + return GetEndpointAddress("TcpCertificateWithSubjectCanonicalNameFqdn.svc/tcp-server-subject-cn-fqdn-cert", protocol: "net.tcp"); } } @@ -691,7 +691,7 @@ public static string NetTcp_SecModeTrans_ClientCredTypeNone_ServerCertValModePee { get { - return GetEndpointAddress("NetTcpCertValModePeerTrust.svc//nettcp-server-cert-valmode-peertrust", protocol: "net.tcp"); + return GetEndpointAddress("NetTcpCertValModePeerTrust.svc/nettcp-server-cert-valmode-peertrust", protocol: "net.tcp"); } } @@ -734,12 +734,12 @@ public static string TcpSoap11WSA10_Address public static string Tcp_SecModeTransWithMessCred_ClientCredTypeCert { - get { return GetEndpointAddress("TcpTransSecMessCredsCert.svc//tcp-message-credentials-cert", protocol: "net.tcp"); } + get { return GetEndpointAddress("TcpTransSecMessCredsCert.svc/tcp-message-credentials-cert", protocol: "net.tcp"); } } public static string Tcp_SecModeTransWithMessCred_ClientCredTypeUserName { - get { return GetEndpointAddress("TcpTransSecMessCredsUserName.svc//tcp-message-credentials-username", protocol: "net.tcp"); } + get { return GetEndpointAddress("TcpTransSecMessCredsUserName.svc/tcp-message-credentials-username", protocol: "net.tcp"); } } public static string ReliableSession_NetTcp diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/AsyncResult.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/AsyncResult.cs deleted file mode 100644 index f6838dfbbfc..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/AsyncResult.cs +++ /dev/null @@ -1,236 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System; -using System.Diagnostics; -using System.Threading; - -/// -/// A generic base class for IAsyncResult implementations -/// that wraps a ManualResetEvent. -/// -abstract class AsyncResult : IAsyncResult -{ - AsyncCallback callback; - object state; - bool completedSynchronously; - bool endCalled; - Exception exception; - bool isCompleted; - ManualResetEvent manualResetEvent; - object thisLock; - - protected AsyncResult(AsyncCallback callback, object state) - { - this.callback = callback; - this.state = state; - this.thisLock = new object(); - } - - public object AsyncState - { - get - { - return state; - } - } - - public WaitHandle AsyncWaitHandle - { - get - { - if (manualResetEvent != null) - { - return manualResetEvent; - } - - lock (ThisLock) - { - if (manualResetEvent == null) - { - manualResetEvent = new ManualResetEvent(isCompleted); - } - } - - return manualResetEvent; - } - } - - public bool CompletedSynchronously - { - get - { - return completedSynchronously; - } - } - - public bool IsCompleted - { - get - { - return isCompleted; - } - } - - object ThisLock - { - get - { - return this.thisLock; - } - } - - // Call this version of complete when your asynchronous operation is complete. This will update the state - // of the operation and notify the callback. - protected void Complete(bool completedSynchronously) - { - if (isCompleted) - { - // It is a bug to call Complete twice. - throw new InvalidOperationException("Cannot call Complete twice"); - } - - this.completedSynchronously = completedSynchronously; - - if (completedSynchronously) - { - // If we completedSynchronously, then there is no chance that the manualResetEvent was created so - // we do not need to worry about a race condition. - Debug.Assert(this.manualResetEvent == null, "No ManualResetEvent should be created for a synchronous AsyncResult."); - this.isCompleted = true; - } - else - { - lock (ThisLock) - { - this.isCompleted = true; - if (this.manualResetEvent != null) - { - this.manualResetEvent.Set(); - } - } - } - - // If the callback throws, there is a bug in the callback implementation - if (callback != null) - { - callback(this); - } - } - - // Call this version of complete if you raise an exception during processing. In addition to notifying - // the callback, it will capture the exception and store it to be thrown during AsyncResult.End. - protected void Complete(bool completedSynchronously, Exception exception) - { - this.exception = exception; - Complete(completedSynchronously); - } - - // End should be called when the End function for the asynchronous operation is complete. It - // ensures the asynchronous operation is complete, and does some common validation. - protected static TAsyncResult End(IAsyncResult result) - where TAsyncResult : AsyncResult - { - if (result == null) - { - throw new ArgumentNullException("result"); - } - - TAsyncResult asyncResult = result as TAsyncResult; - - if (asyncResult == null) - { - throw new ArgumentException("Invalid async result.", "result"); - } - - if (asyncResult.endCalled) - { - throw new InvalidOperationException("Async object already ended."); - } - - asyncResult.endCalled = true; - - if (!asyncResult.isCompleted) - { - asyncResult.AsyncWaitHandle.WaitOne(); - } - - if (asyncResult.manualResetEvent != null) - { - asyncResult.manualResetEvent.Dispose(); - } - - if (asyncResult.exception != null) - { - throw asyncResult.exception; - } - - return asyncResult; - } -} - -//An AsyncResult that completes as soon as it is instantiated. -class CompletedAsyncResult : AsyncResult -{ - public CompletedAsyncResult(AsyncCallback callback, object state) - : base(callback, state) - { - Complete(true); - } - - public static void End(IAsyncResult result) - { - AsyncResult.End(result); - } -} - -//A strongly typed AsyncResult -abstract class TypedAsyncResult : AsyncResult -{ - T data; - - protected TypedAsyncResult(AsyncCallback callback, object state) - : base(callback, state) - { - } - - public T Data - { - get { return data; } - } - - protected void Complete(T data, bool completedSynchronously) - { - this.data = data; - Complete(completedSynchronously); - } - - public static T End(IAsyncResult result) - { - TypedAsyncResult typedResult = AsyncResult.End>(result); - return typedResult.Data; - } -} - -//A strongly typed AsyncResult that completes as soon as it is instantiated. -class TypedCompletedAsyncResult : TypedAsyncResult -{ - public TypedCompletedAsyncResult(T data, AsyncCallback callback, object state) - : base(callback, state) - { - Complete(data, true); - } - - public new static T End(IAsyncResult result) - { - TypedCompletedAsyncResult completedResult = result as TypedCompletedAsyncResult; - if (completedResult == null) - { - throw new ArgumentException("Invalid async result.", "result"); - } - - return TypedAsyncResult.End(completedResult); - } -} diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/ChainedAsyncResult.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/ChainedAsyncResult.cs deleted file mode 100644 index bb310b27ab2..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/ChainedAsyncResult.cs +++ /dev/null @@ -1,114 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System; - - internal delegate IAsyncResult ChainedBeginHandler(TimeSpan timeout, AsyncCallback asyncCallback, object state); - internal delegate void ChainedEndHandler(IAsyncResult result); - -class ChainedAsyncResult : AsyncResult -{ - ChainedBeginHandler begin2; - ChainedEndHandler end1; - ChainedEndHandler end2; - TimeoutHelper timeoutHelper; - static AsyncCallback begin1Callback = new AsyncCallback(Begin1Callback); - static AsyncCallback begin2Callback = new AsyncCallback(Begin2Callback); - - protected ChainedAsyncResult(TimeSpan timeout, AsyncCallback callback, object state) - : base(callback, state) - { - this.timeoutHelper = new TimeoutHelper(timeout); - } - - public ChainedAsyncResult(TimeSpan timeout, AsyncCallback callback, object state, ChainedBeginHandler begin1, ChainedEndHandler end1, ChainedBeginHandler begin2, ChainedEndHandler end2) - : base(callback, state) - { - this.timeoutHelper = new TimeoutHelper(timeout); - Begin(begin1, end1, begin2, end2); - } - - protected void Begin(ChainedBeginHandler begin1, ChainedEndHandler end1, ChainedBeginHandler begin2, ChainedEndHandler end2) - { - this.end1 = end1; - this.begin2 = begin2; - this.end2 = end2; - - IAsyncResult result = begin1(this.timeoutHelper.RemainingTime(), begin1Callback, this); - if (!result.CompletedSynchronously) - return; - - if (Begin1Completed(result)) - { - this.Complete(true); - } - } - - static void Begin1Callback(IAsyncResult result) - { - if (result.CompletedSynchronously) - return; - - ChainedAsyncResult thisPtr = (ChainedAsyncResult)result.AsyncState; - - bool completeSelf = false; - Exception completeException = null; - - try - { - completeSelf = thisPtr.Begin1Completed(result); - } - catch (Exception exception) - { - completeSelf = true; - completeException = exception; - } - - if (completeSelf) - { - thisPtr.Complete(false, completeException); - } - } - - bool Begin1Completed(IAsyncResult result) - { - end1(result); - - result = begin2(this.timeoutHelper.RemainingTime(), begin2Callback, this); - if (!result.CompletedSynchronously) - { - return false; - } - - end2(result); - return true; - } - - static void Begin2Callback(IAsyncResult result) - { - if (result.CompletedSynchronously) - return; - - ChainedAsyncResult thisPtr = (ChainedAsyncResult)result.AsyncState; - - Exception completeException = null; - - try - { - thisPtr.end2(result); - } - catch (Exception exception) - { - completeException = exception; - } - - thisPtr.Complete(false, completeException); - } - - public static void End(IAsyncResult result) - { - AsyncResult.End(result); - } -} diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/ChannelMessageInterceptor.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/ChannelMessageInterceptor.cs deleted file mode 100644 index 0331b08d791..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/ChannelMessageInterceptor.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System.ServiceModel.Channels; - -public abstract class ChannelMessageInterceptor -{ - public virtual void OnSend(ref Message message) { } - public virtual void OnReceive(ref Message message) { } - - public abstract ChannelMessageInterceptor Clone(); -} diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/Extensibility.MessageInterceptor.IntegrationTests.csproj b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/Extensibility.MessageInterceptor.IntegrationTests.csproj deleted file mode 100644 index 0067cc32adc..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/Extensibility.MessageInterceptor.IntegrationTests.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - $(ScenarioTestTargetFrameworks) - false - true - false - - - - - - - - - - diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingBindingElement.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingBindingElement.cs deleted file mode 100644 index bfb5d1c26c1..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingBindingElement.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System; -using System.ServiceModel.Channels; - -public class InterceptingBindingElement : BindingElement -{ - ChannelMessageInterceptor interceptor; - - public InterceptingBindingElement(ChannelMessageInterceptor interceptor) - { - this.interceptor = interceptor; - } - - protected InterceptingBindingElement(InterceptingBindingElement other) - : base(other) - { - this.interceptor = other.Interceptor; - } - - public ChannelMessageInterceptor Interceptor - { - get - { - if (this.interceptor != null) - { - return this.interceptor.Clone(); - } - else - { - return new NullMessageInterceptor(); - } - } - } - - public override BindingElement Clone() - { - return new InterceptingBindingElement(this); - } - - public override bool CanBuildChannelFactory(BindingContext context) - { - return context.CanBuildInnerChannelFactory(); - } - - public override IChannelFactory BuildChannelFactory(BindingContext context) - { - return new InterceptingChannelFactory(this.Interceptor, context); - } - - public override T GetProperty(BindingContext context) - { - if (typeof(T) == typeof(ChannelMessageInterceptor)) - { - return (T)(object)this.Interceptor; - } - - return context.GetInnerProperty(); - } - - class NullMessageInterceptor : ChannelMessageInterceptor - { - public override ChannelMessageInterceptor Clone() - { - return new NullMessageInterceptor(); - } - } -} - diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingChannelBase.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingChannelBase.cs deleted file mode 100644 index a97c90688b5..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingChannelBase.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System; -using System.ServiceModel.Channels; - -/// -/// Base channel class that uses an ChannelMessageInterceptor -/// -class InterceptingChannelBase : ChannelBase - where TChannel : class, IChannel -{ - ChannelMessageInterceptor interceptor; - TChannel innerChannel; - - protected InterceptingChannelBase( - ChannelManagerBase manager, ChannelMessageInterceptor interceptor, TChannel innerChannel) - : base(manager) - { - if (innerChannel == null) - { - throw new ArgumentException("InterceptingChannelBase requires a non-null inner channel.", "innerChannel"); - } - - this.interceptor = interceptor; - this.innerChannel = innerChannel; - } - - protected TChannel InnerChannel - { - get - { - return this.innerChannel; - } - } - - public override T GetProperty() - { - T baseProperty = base.GetProperty(); - if (baseProperty != null) - { - return baseProperty; - } - - return this.InnerChannel.GetProperty(); - } - - protected override void OnAbort() - { - this.innerChannel.Abort(); - } - - protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) - { - return this.innerChannel.BeginClose(timeout, callback, state); - } - - protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) - { - return this.innerChannel.BeginOpen(timeout, callback, state); - } - - protected override void OnClose(TimeSpan timeout) - { - this.innerChannel.Close(timeout); - } - - protected override void OnEndClose(IAsyncResult result) - { - this.innerChannel.EndClose(result); - } - - protected override void OnEndOpen(IAsyncResult result) - { - this.innerChannel.EndOpen(result); - } - - protected override void OnOpen(TimeSpan timeout) - { - this.innerChannel.Open(timeout); - } - - protected void OnReceive(ref Message message) - { - this.interceptor.OnReceive(ref message); - } - - protected void OnSend(ref Message message) - { - this.interceptor.OnSend(ref message); - } -} diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingChannelFactory.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingChannelFactory.cs deleted file mode 100644 index daf69e979fb..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingChannelFactory.cs +++ /dev/null @@ -1,391 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System; -using System.ServiceModel; -using System.ServiceModel.Channels; - -/// -/// ChannelFactory that performs message Interception -/// -class InterceptingChannelFactory - : ChannelFactoryBase -{ - ChannelMessageInterceptor interceptor; - IChannelFactory innerChannelFactory; - - public InterceptingChannelFactory(ChannelMessageInterceptor interceptor, BindingContext context) - { - this.interceptor = interceptor; - this.innerChannelFactory = context.BuildInnerChannelFactory(); - if (this.innerChannelFactory == null) - { - throw new InvalidOperationException("InterceptingChannelFactory requires an inner IChannelFactory."); - } - } - - public ChannelMessageInterceptor Interceptor - { - get { return this.interceptor; } - } - - public override T GetProperty() - { - T baseProperty = base.GetProperty(); - if (baseProperty != null) - { - return baseProperty; - } - - return this.innerChannelFactory.GetProperty(); - } - - protected override void OnOpen(TimeSpan timeout) - { - this.innerChannelFactory.Open(timeout); - } - - protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) - { - return this.innerChannelFactory.BeginOpen(timeout, callback, state); - } - - protected override void OnEndOpen(IAsyncResult result) - { - this.innerChannelFactory.EndOpen(result); - } - - protected override void OnAbort() - { - base.OnAbort(); - this.innerChannelFactory.Abort(); - } - - protected override void OnClose(TimeSpan timeout) - { - TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); - base.OnClose(timeoutHelper.RemainingTime()); - this.innerChannelFactory.Close(timeoutHelper.RemainingTime()); - } - - protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) - { - return new ChainedAsyncResult(timeout, callback, state, base.OnBeginClose, base.OnEndClose, innerChannelFactory.BeginClose, innerChannelFactory.EndClose); - } - - protected override void OnEndClose(IAsyncResult result) - { - ChainedAsyncResult.End(result); - } - - protected override TChannel OnCreateChannel(EndpointAddress to, Uri via) - { - TChannel innerChannel = this.innerChannelFactory.CreateChannel(to, via); - if (typeof(TChannel) == typeof(IOutputChannel)) - { - return (TChannel)(object)new InterceptingOutputChannel(this, (IOutputChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IRequestChannel)) - { - return (TChannel)(object)new InterceptingRequestChannel(this, (IRequestChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IDuplexChannel)) - { - return (TChannel)(object)new InterceptingDuplexChannel(this, Interceptor, (IDuplexChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IOutputSessionChannel)) - { - return (TChannel)(object)new InterceptingOutputSessionChannel(this, (IOutputSessionChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IRequestSessionChannel)) - { - return (TChannel)(object)new InterceptingRequestSessionChannel(this, - (IRequestSessionChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IDuplexSessionChannel)) - { - return (TChannel)(object)new InterceptingDuplexSessionChannel(this, Interceptor, (IDuplexSessionChannel)innerChannel); - } - - throw new InvalidOperationException(); - } - - class InterceptingOutputChannel - : InterceptingChannelBase, IOutputChannel - { - public InterceptingOutputChannel(InterceptingChannelFactory factory, IOutputChannel innerChannel) - : base(factory, factory.Interceptor, innerChannel) - { - // empty - } - - public EndpointAddress RemoteAddress - { - get - { - return this.InnerChannel.RemoteAddress; - } - } - - public Uri Via - { - get - { - return this.InnerChannel.Via; - } - } - - public IAsyncResult BeginSend(Message message, AsyncCallback callback, object state) - { - return BeginSend(message, DefaultSendTimeout, callback, state); - } - - public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state) - { - this.OnSend(ref message); - return new SendAsyncResult(this, message, timeout, callback, state); - } - - public void EndSend(IAsyncResult result) - { - SendAsyncResult.End(result); - } - - public void Send(Message message) - { - Send(message, DefaultSendTimeout); - } - - public void Send(Message message, TimeSpan timeout) - { - base.OnSend(ref message); - - if (message != null) - { - this.InnerChannel.Send(message, timeout); - } - } - - class SendAsyncResult : AsyncResult - { - IOutputChannel channel; - AsyncCallback sendCallback = new AsyncCallback(OnSend); - - public SendAsyncResult(IOutputChannel channel, Message message, TimeSpan timeout, AsyncCallback callback, object state) - : base(callback, state) - { - if (message != null) - { - this.channel = channel; - - IAsyncResult sendResult = channel.BeginSend(message, timeout, sendCallback, this); - if (!sendResult.CompletedSynchronously) - { - return; - } - - CompleteSend(sendResult); - } - - base.Complete(true); - } - - void CompleteSend(IAsyncResult result) - { - channel.EndSend(result); - } - - static void OnSend(IAsyncResult result) - { - if (result.CompletedSynchronously) - { - return; - } - - SendAsyncResult thisPtr = (SendAsyncResult)result.AsyncState; - Exception completionException = null; - - try - { - thisPtr.CompleteSend(result); - } - catch (Exception e) - { - completionException = e; - } - - thisPtr.Complete(false, completionException); - } - - public static void End(IAsyncResult result) - { - AsyncResult.End(result); - } - } - } - - class InterceptingRequestChannel - : InterceptingChannelBase, IRequestChannel - { - public InterceptingRequestChannel( - InterceptingChannelFactory factory, IRequestChannel innerChannel) - : base(factory, factory.Interceptor, innerChannel) - { - // empty - } - - public EndpointAddress RemoteAddress - { - get - { - return this.InnerChannel.RemoteAddress; - } - } - - public Uri Via - { - get - { - return this.InnerChannel.Via; - } - } - - public IAsyncResult BeginRequest(Message message, AsyncCallback callback, object state) - { - return BeginRequest(message, this.DefaultSendTimeout, callback, state); - } - - public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state) - { - base.OnSend(ref message); - return new RequestAsyncResult(this, message, timeout, callback, state); - } - - public Message EndRequest(IAsyncResult result) - { - Message reply = RequestAsyncResult.End(result); - this.OnReceive(ref reply); - return reply; - } - - public Message Request(Message message) - { - return Request(message, this.DefaultSendTimeout); - } - - public Message Request(Message message, TimeSpan timeout) - { - this.OnSend(ref message); - Message reply = null; - if (message != null) - { - reply = this.InnerChannel.Request(message); - } - - this.OnReceive(ref reply); - return reply; - } - - class RequestAsyncResult : AsyncResult - { - Message replyMessage; - InterceptingRequestChannel channel; - AsyncCallback requestCallback = new AsyncCallback(OnRequest); - - public RequestAsyncResult(InterceptingRequestChannel channel, Message message, TimeSpan timeout, AsyncCallback callback, object state) - : base(callback, state) - { - if (message != null) - { - this.channel = channel; - - IAsyncResult requestResult = channel.InnerChannel.BeginRequest(message, timeout, requestCallback, this); - if (!requestResult.CompletedSynchronously) - { - return; - } - - CompleteRequest(requestResult); - } - - base.Complete(true); - } - - void CompleteRequest(IAsyncResult result) - { - replyMessage = channel.InnerChannel.EndRequest(result); - } - - static void OnRequest(IAsyncResult result) - { - if (result.CompletedSynchronously) - { - return; - } - - RequestAsyncResult thisPtr = (RequestAsyncResult)result.AsyncState; - Exception completionException = null; - - try - { - thisPtr.CompleteRequest(result); - } - catch (Exception e) - { - completionException = e; - } - - thisPtr.Complete(false, completionException); - } - - public static Message End(IAsyncResult result) - { - RequestAsyncResult thisPtr = AsyncResult.End(result); - return thisPtr.replyMessage; - } - } - - } - - class InterceptingOutputSessionChannel : InterceptingOutputChannel, IOutputSessionChannel - { - IOutputSessionChannel innerSessionChannel; - - public InterceptingOutputSessionChannel( - InterceptingChannelFactory factory, IOutputSessionChannel innerChannel) - : base(factory, innerChannel) - { - this.innerSessionChannel = innerChannel; - } - - public IOutputSession Session - { - get - { - return this.innerSessionChannel.Session; - } - } - } - - class InterceptingRequestSessionChannel : InterceptingRequestChannel, IRequestSessionChannel - { - IRequestSessionChannel innerSessionChannel; - - public InterceptingRequestSessionChannel( - InterceptingChannelFactory factory, IRequestSessionChannel innerChannel) - : base(factory, innerChannel) - { - this.innerSessionChannel = innerChannel; - } - - public IOutputSession Session - { - get - { - return this.innerSessionChannel.Session; - } - } - } -} diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingDuplexChannel.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingDuplexChannel.cs deleted file mode 100644 index 018808336dd..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/InterceptingDuplexChannel.cs +++ /dev/null @@ -1,335 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System; -using System.ServiceModel; -using System.ServiceModel.Channels; - -class InterceptingInputChannel - : InterceptingChannelBase, IInputChannel - where TChannel : class, IInputChannel -{ - public InterceptingInputChannel( - ChannelManagerBase manager, ChannelMessageInterceptor interceptor, TChannel innerChannel) - : base(manager, interceptor, innerChannel) - { - // empty - } - - public EndpointAddress LocalAddress - { - get - { - return this.InnerChannel.LocalAddress; - } - } - - bool ProcessReceivedMessage(ref Message message) - { - Message originalMessage = message; - this.OnReceive(ref message); - return (message != null || originalMessage == null); - } - - public Message Receive() - { - return Receive(DefaultReceiveTimeout); - } - - public Message Receive(TimeSpan timeout) - { - Message message; - while (true) - { - message = this.InnerChannel.Receive(timeout); - if (ProcessReceivedMessage(ref message)) - { - break; - } - } - - return message; - } - - public IAsyncResult BeginReceive(AsyncCallback callback, object state) - { - return BeginReceive(DefaultReceiveTimeout, callback, state); - } - - public IAsyncResult BeginReceive(TimeSpan timeout, AsyncCallback callback, object state) - { - ReceiveAsyncResult result = new ReceiveAsyncResult(this, timeout, callback, state); - result.Begin(); - return result; - } - - public Message EndReceive(IAsyncResult result) - { - return ReceiveAsyncResult.End(result); - } - - public bool TryReceive(TimeSpan timeout, out Message message) - { - bool result; - while (true) - { - result = this.InnerChannel.TryReceive(timeout, out message); - if (ProcessReceivedMessage(ref message)) - { - break; - } - } - - return result; - } - - public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state) - { - TryReceiveAsyncResult result = new TryReceiveAsyncResult(this, timeout, callback, state); - result.Begin(); - return result; - } - - public bool EndTryReceive(IAsyncResult result, out Message message) - { - return TryReceiveAsyncResult.End(result, out message); - } - - public bool WaitForMessage(TimeSpan timeout) - { - return this.InnerChannel.WaitForMessage(timeout); - } - - public IAsyncResult BeginWaitForMessage(TimeSpan timeout, AsyncCallback callback, object state) - { - return this.InnerChannel.BeginWaitForMessage(timeout, callback, state); - } - - public bool EndWaitForMessage(IAsyncResult result) - { - return this.InnerChannel.EndWaitForMessage(result); - } - - abstract class ReceiveAsyncResultBase : AsyncResult - where TInputChannel : class, IInputChannel - { - Message message; - InterceptingInputChannel channel; - AsyncCallback onReceive; - - protected ReceiveAsyncResultBase(InterceptingInputChannel channel, - AsyncCallback callback, object state) - : base(callback, state) - { - this.channel = channel; - this.onReceive = new AsyncCallback(OnReceive); - } - - protected Message Message - { - get { return this.message; } - } - - public void Begin() - { - IAsyncResult result = BeginReceive(onReceive, null); - if (result.CompletedSynchronously) - { - if (HandleReceiveComplete(result)) - { - base.Complete(true); - } - } - } - - protected abstract IAsyncResult BeginReceive(AsyncCallback callback, object state); - protected abstract Message EndReceive(IAsyncResult result); - - bool HandleReceiveComplete(IAsyncResult result) - { - while (true) - { - this.message = EndReceive(result); - if (channel.ProcessReceivedMessage(ref message)) - { - return true; - } - - // try again - result = BeginReceive(onReceive, null); - if (!result.CompletedSynchronously) - { - return false; - } - } - } - - void OnReceive(IAsyncResult result) - { - if (result.CompletedSynchronously) - { - return; - } - - bool completeSelf = false; - Exception completeException = null; - try - { - completeSelf = HandleReceiveComplete(result); - } - catch (Exception e) - { - completeException = e; - completeSelf = true; - } - - if (completeSelf) - { - base.Complete(false, completeException); - } - } - } - - class TryReceiveAsyncResult : ReceiveAsyncResultBase - where TInputChannel : class, IInputChannel - { - TInputChannel innerChannel; - TimeSpan timeout; - bool returnValue; - - public TryReceiveAsyncResult(InterceptingInputChannel channel, TimeSpan timeout, - AsyncCallback callback, object state) - : base(channel, callback, state) - { - this.innerChannel = channel.InnerChannel; - this.timeout = timeout; - } - - protected override IAsyncResult BeginReceive(AsyncCallback callback, object state) - { - return this.innerChannel.BeginTryReceive(this.timeout, callback, state); - } - - protected override Message EndReceive(IAsyncResult result) - { - Message message; - this.returnValue = this.innerChannel.EndTryReceive(result, out message); - return message; - } - - public static bool End(IAsyncResult result, out Message message) - { - TryReceiveAsyncResult thisPtr = AsyncResult.End>(result); - message = thisPtr.Message; - return thisPtr.returnValue; - } - } - - class ReceiveAsyncResult : ReceiveAsyncResultBase - where TInputChannel : class, IInputChannel - { - TInputChannel innerChannel; - TimeSpan timeout; - - public ReceiveAsyncResult(InterceptingInputChannel channel, TimeSpan timeout, - AsyncCallback callback, object state) - : base(channel, callback, state) - { - this.innerChannel = channel.InnerChannel; - this.timeout = timeout; - } - - protected override IAsyncResult BeginReceive(AsyncCallback callback, object state) - { - return this.innerChannel.BeginReceive(this.timeout, callback, state); - } - - protected override Message EndReceive(IAsyncResult result) - { - return this.innerChannel.EndReceive(result); - } - - public static Message End(IAsyncResult result) - { - ReceiveAsyncResult thisPtr = AsyncResult.End>(result); - return thisPtr.Message; - } - } -} - -class InterceptingDuplexChannel - : InterceptingInputChannel, IDuplexChannel -{ - public InterceptingDuplexChannel( - ChannelManagerBase manager, ChannelMessageInterceptor interceptor, IDuplexChannel innerChannel) - : base(manager, interceptor, innerChannel) - { - // empty - } - - public EndpointAddress RemoteAddress - { - get - { - return this.InnerChannel.RemoteAddress; - } - } - - public Uri Via - { - get - { - return this.InnerChannel.Via; - } - } - - public void Send(Message message) - { - Send(message, DefaultSendTimeout); - } - - public void Send(Message message, TimeSpan timeout) - { - this.OnSend(ref message); - this.InnerChannel.Send(message, timeout); - } - - public IAsyncResult BeginSend(Message message, AsyncCallback callback, object state) - { - return BeginSend(message, DefaultSendTimeout, callback, state); - } - - public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state) - { - this.OnSend(ref message); - return this.InnerChannel.BeginSend(message, timeout, callback, state); - } - - public void EndSend(IAsyncResult result) - { - this.InnerChannel.EndSend(result); - } -} - - -class InterceptingDuplexSessionChannel : InterceptingDuplexChannel, IDuplexSessionChannel -{ - IDuplexSessionChannel innerSessionChannel; - - public InterceptingDuplexSessionChannel( - ChannelManagerBase manager, ChannelMessageInterceptor interceptor, IDuplexSessionChannel innerChannel) - : base(manager, interceptor, innerChannel) - { - this.innerSessionChannel = innerChannel; - } - - public IDuplexSession Session - { - get - { - return this.innerSessionChannel.Session; - } - } -} diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/MessageInterceptorTests.4.1.1.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/MessageInterceptorTests.4.1.1.cs deleted file mode 100644 index 35ae0addf1e..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/MessageInterceptorTests.4.1.1.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System; -using System.ServiceModel; -using System.ServiceModel.Channels; -using Infrastructure.Common; -using Xunit; - -public partial class MessageInterceptorTests : ConditionalWcfTest -{ - public class MessageModifier : ChannelMessageInterceptor - { - int send = 0; - - public override void OnSend(ref Message msg) - { - send++; - if (send % 2 == 0) - { - // Add extra header so that when the message arrives on service side, the message won't be dropped - msg.Headers.Add(MessageHeader.CreateHeader("ByPass", "urn:InterceptorNamespace", "ByPassPassword")); - } - } - - public override ChannelMessageInterceptor Clone() - { - return new MessageModifier(); - } - } - - [WcfFact] - [OuterLoop] - public static void CustomBinding_Message_Interceptor() - { - ChannelFactory factory = null; - IWcfChannelExtensibilityContract serviceProxy = null; - - try - { - // *** SETUP *** \\ - CustomBinding binding = new CustomBinding( - new InterceptingBindingElement(new MessageModifier()), - new HttpTransportBindingElement()); - - factory = new ChannelFactory(binding, new EndpointAddress(Endpoints.HttpBaseAddress_ChannelExtensibility)); - serviceProxy = factory.CreateChannel(); - - // *** EXECUTE & VALIDATE *** \\ - int[] windSpeeds = new int[] { 100, 90, 80, 70, 60, 50, 40, 30, 20, 10 }; - for (int i = 0; i < 10; i++) - { - serviceProxy.ReportWindSpeed(windSpeeds[i]); - } - - // *** CLEANUP *** \\ - ((ICommunicationObject)serviceProxy).Close(); - factory.Close(); - } - finally - { - // *** ENSURE CLEANUP *** \\ - ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); - } - } -} \ No newline at end of file diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/TimeoutHelper.cs b/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/TimeoutHelper.cs deleted file mode 100644 index ce1051e67a7..00000000000 --- a/src/System.Private.ServiceModel/tests/Scenarios/Extensibility/MessageInterceptor/TimeoutHelper.cs +++ /dev/null @@ -1,196 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System; -using System.Threading; - -public struct TimeoutHelper -{ - public static TimeSpan DefaultTimeout { get { return TimeSpan.FromMinutes(2); } } - public static TimeSpan DefaultShortTimeout { get { return TimeSpan.FromSeconds(4); } } - public static TimeSpan Infinite { get { return TimeSpan.MaxValue; } } - DateTime deadline; - TimeSpan originalTimeout; - - public TimeoutHelper(TimeSpan timeout) - { - if (timeout < TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException("timeout"); - } - - this.originalTimeout = timeout; - if (timeout == TimeSpan.MaxValue) - { - this.deadline = DateTime.MaxValue; - } - else - { - this.deadline = DateTime.UtcNow + timeout; - } - } - - public TimeSpan OriginalTimeout - { - get { return this.originalTimeout; } - } - - public TimeSpan RemainingTime() - { - if (this.deadline == DateTime.MaxValue) - { - return TimeSpan.MaxValue; - } - else - { - TimeSpan remaining = this.deadline - DateTime.UtcNow; - if (remaining <= TimeSpan.Zero) - { - return TimeSpan.Zero; - } - else - { - return remaining; - } - } - } - public void SetTimer(TimerCallback callback, Object state) - { - Timer timer = new Timer(callback, state, TimeoutHelper.ToMilliseconds(this.RemainingTime()), Timeout.Infinite); - } - - public static TimeSpan FromMilliseconds(int milliseconds) - { - if (milliseconds == Timeout.Infinite) - { - return TimeSpan.MaxValue; - } - else - { - return TimeSpan.FromMilliseconds(milliseconds); - } - } - - public static int ToMilliseconds(TimeSpan timeout) - { - if (timeout == TimeSpan.MaxValue) - { - return Timeout.Infinite; - } - else - { - long ticks = Ticks.FromTimeSpan(timeout); - if (ticks / TimeSpan.TicksPerMillisecond > int.MaxValue) - { - return int.MaxValue; - } - return Ticks.ToMilliseconds(ticks); - } - } - - public static TimeSpan Add(TimeSpan timeout1, TimeSpan timeout2) - { - return Ticks.ToTimeSpan(Ticks.Add(Ticks.FromTimeSpan(timeout1), Ticks.FromTimeSpan(timeout2))); - } - - public static DateTime Add(DateTime time, TimeSpan timeout) - { - if (timeout >= TimeSpan.Zero && DateTime.MaxValue - time <= timeout) - { - return DateTime.MaxValue; - } - if (timeout <= TimeSpan.Zero && DateTime.MinValue - time >= timeout) - { - return DateTime.MinValue; - } - return time + timeout; - } - - public static DateTime Subtract(DateTime time, TimeSpan timeout) - { - return Add(time, TimeSpan.Zero - timeout); - } - - public static TimeSpan Divide(TimeSpan timeout, int factor) - { - if (timeout == TimeSpan.MaxValue) - { - return TimeSpan.MaxValue; - } - - return Ticks.ToTimeSpan((Ticks.FromTimeSpan(timeout) / factor) + 1); - } - - public static bool WaitOne(WaitHandle waitHandle, TimeSpan timeout, bool exitSync) - { - if (timeout == TimeSpan.MaxValue) - { - waitHandle.WaitOne(); - return true; - } - else - { - TimeSpan maxWait = TimeSpan.FromMilliseconds(Int32.MaxValue); - - while (timeout > maxWait) - { - bool signaled = waitHandle.WaitOne(maxWait); - - if (signaled) - { - return true; - } - - timeout -= maxWait; - } - - return waitHandle.WaitOne(timeout); - } - } - - static class Ticks - { - public static long FromMilliseconds(int milliseconds) - { - return (long)milliseconds * TimeSpan.TicksPerMillisecond; - } - - public static int ToMilliseconds(long ticks) - { - return checked((int)(ticks / TimeSpan.TicksPerMillisecond)); - } - - public static long FromTimeSpan(TimeSpan duration) - { - return duration.Ticks; - } - - public static TimeSpan ToTimeSpan(long ticks) - { - return new TimeSpan(ticks); - } - - public static long Add(long firstTicks, long secondTicks) - { - if (firstTicks == long.MaxValue || firstTicks == long.MinValue) - { - return firstTicks; - } - if (secondTicks == long.MaxValue || secondTicks == long.MinValue) - { - return secondTicks; - } - if (firstTicks >= 0 && long.MaxValue - firstTicks <= secondTicks) - { - return long.MaxValue - 1; - } - if (firstTicks <= 0 && long.MinValue - firstTicks >= secondTicks) - { - return long.MinValue + 1; - } - return checked(firstTicks + secondTicks); - } - } -} diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.sln b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.sln index 3f6b91d2469..e90cafbf4e0 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.sln +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.sln @@ -1,22 +1,31 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.438 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34321.82 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CertificateGenerator", "CertificateGenerator.csproj", "{99C31CA4-03FF-4378-93E3-85389341C6C3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CertificateGeneratorLibrary", "CertificateGeneratorLibrary\CertificateGeneratorLibrary.csproj", "{07CA0DD3-755A-47B0-AA32-ADC249227B0F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CertificateGenerator", "CertificateGenerator\CertificateGenerator.csproj", "{F8E24E54-71E3-46C5-B4A7-92E3AE36CBD2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {99C31CA4-03FF-4378-93E3-85389341C6C3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {99C31CA4-03FF-4378-93E3-85389341C6C3}.Release|Any CPU.Build.0 = Release|Any CPU + {07CA0DD3-755A-47B0-AA32-ADC249227B0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07CA0DD3-755A-47B0-AA32-ADC249227B0F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07CA0DD3-755A-47B0-AA32-ADC249227B0F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07CA0DD3-755A-47B0-AA32-ADC249227B0F}.Release|Any CPU.Build.0 = Release|Any CPU + {F8E24E54-71E3-46C5-B4A7-92E3AE36CBD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8E24E54-71E3-46C5-B4A7-92E3AE36CBD2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8E24E54-71E3-46C5-B4A7-92E3AE36CBD2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8E24E54-71E3-46C5-B4A7-92E3AE36CBD2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {F6B453F0-0829-4C2F-BBB6-9B22EE6A1E58} + SolutionGuid = {CEC7E1AA-8CED-4E37-A8AD-AC8DD206A54B} EndGlobalSection EndGlobal diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/App.config b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/App.config similarity index 100% rename from src/System.Private.ServiceModel/tools/CertificateGenerator/App.config rename to src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/App.config diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.csproj b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/CertificateGenerator.csproj similarity index 63% rename from src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.csproj rename to src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/CertificateGenerator.csproj index 014d322e894..aa0f59bf3c2 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.csproj +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/CertificateGenerator.csproj @@ -1,4 +1,4 @@ - + net471 @@ -6,7 +6,7 @@ - + diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/Program.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/Program.cs new file mode 100644 index 00000000000..f75744c1033 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator/Program.cs @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Configuration; + +namespace CertUtil +{ + internal class Program + { + private static string s_testserverbase = string.Empty; + private static string s_crlFileLocation = string.Empty; + private static TimeSpan s_validatePeriod; + + private static void Usage() + { + Console.WriteLine("Supported argument is -Uninstall"); + Console.WriteLine(" -help"); + } + private static int Main(string[] args) + { + ApplyAppSettings(); + + if (args.Length > 0) + { + if (string.Compare(args[0], "-Uninstall", true) == 0) + { + CertificateGeneratorLibrary.UninstallAllCerts(); + return 0; + } + else if (string.Compare(args[0], "-help", true) == 0) + { + Usage(); + return 0; + } + else + { + Usage(); + return 1; + } + } + + CertificateGeneratorLibrary.SetupCerts(s_testserverbase, s_validatePeriod, s_crlFileLocation); + + return 0; + } + + private static void ApplyAppSettings() + { + var appSettings = ConfigurationManager.AppSettings; + s_testserverbase = appSettings["testserverbase"] ?? string.Empty; + s_validatePeriod = TimeSpan.FromDays(int.Parse(appSettings["CertExpirationInDay"])); + s_crlFileLocation = appSettings["CrlFileLocation"]; + } + } +} diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateCreationSettings.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateCreationSettings.cs similarity index 100% rename from src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateCreationSettings.cs rename to src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateCreationSettings.cs diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGenerator.cs similarity index 92% rename from src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.cs rename to src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGenerator.cs index 876878b6818..5680c8a0e46 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.cs +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGenerator.cs @@ -4,10 +4,12 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Crypto; @@ -44,10 +46,10 @@ public class CertificateGenerator // Give the cert a grace period in case there's a time skew between machines private readonly TimeSpan _gracePeriod = TimeSpan.FromHours(1); - private const string _authorityCanonicalName = "DO_NOT_TRUST_WcfBridgeRootCA"; + private readonly string _authorityCanonicalName = "DO_NOT_TRUST_WcfBridgeRootCA"; private readonly string _signatureAlgorithm = Org.BouncyCastle.Asn1.Pkcs.PkcsObjectIdentifiers.Sha256WithRsaEncryption.Id; - private const string _upnObjectId = "1.3.6.1.4.1.311.20.2.3"; - private const int _keyLengthInBits = 2048; + private readonly string _upnObjectId = "1.3.6.1.4.1.311.20.2.3"; + private readonly int _keyLengthInBits = 2048; private static readonly X509V3CertificateGenerator s_certGenerator = new X509V3CertificateGenerator(); private static readonly X509V2CrlGenerator s_crlGenerator = new X509V2CrlGenerator(); @@ -232,6 +234,24 @@ public X509CertificateContainer CreateUserCertificate(CertificateCreationSetting return CreateCertificate(false, false, _authorityCertificate.InternalCertificate, creationSettings); } + public static BigInteger HashFriendlyName(string input) + { + using (SHA256 sha256 = SHA256.Create()) + { + // Convert the input string to a byte array + byte[] inputBytes = Encoding.UTF8.GetBytes(input); + + // Compute the hash value of the input bytes, and take the first 20 bytes + byte[] hashBytes = sha256.ComputeHash(inputBytes).Take(20).ToArray(); + + // return a Positive BigInt of the hash + var bigInteger = new BigInteger(1, hashBytes.ToArray()); + return bigInteger; + } + } + + public static string HashFriendlyNameToString(string input) => HashFriendlyName(input).ToString(16).ToUpper(); + // Only the ctor should be calling with isAuthority = true // if isAuthority, value for isMachineCert doesn't matter private X509CertificateContainer CreateCertificate(bool isAuthority, bool isMachineCert, X509Certificate signingCertificate, CertificateCreationSettings certificateCreationSettings) @@ -285,7 +305,17 @@ private X509CertificateContainer CreateCertificate(bool isAuthority, bool isMach // Tag on the generation time to prevent caching of the cert CRL in Linux X509Name authorityX509Name = CreateX509Name(string.Format("{0} {1}", _authorityCanonicalName, DateTime.Now.ToString("s"))); - var serialNum = new BigInteger(64 /*sizeInBits*/, _random).Abs(); + BigInteger serialNum; + + // Search by serial number in Linux/MacOS + if (!CertificateHelper.CurrentOperatingSystem.IsWindows() && certificateCreationSettings.FriendlyName != null) + { + serialNum = HashFriendlyName(certificateCreationSettings.FriendlyName); + } + else + { + serialNum = new BigInteger(64 /*sizeInBits*/, _random).Abs(); + } var keyPair = isAuthority ? _authorityKeyPair : _keyPairGenerator.GenerateKeyPair(); if (isAuthority) @@ -304,7 +334,7 @@ private X509CertificateContainer CreateCertificate(bool isAuthority, bool isMach else { X509Name subjectName = CreateX509Name(subject); - s_certGenerator.SetIssuerDN(PrincipalUtilities.GetSubjectX509Principal(signingCertificate)); + s_certGenerator.SetIssuerDN(signingCertificate.SubjectDN); s_certGenerator.SetSubjectDN(subjectName); s_certGenerator.AddExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(_authorityKeyPair.Public)); @@ -321,7 +351,7 @@ private X509CertificateContainer CreateCertificate(bool isAuthority, bool isMach s_certGenerator.AddExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(isAuthority)); if (certificateCreationSettings.EKU == null || certificateCreationSettings.EKU.Count == 0) { - s_certGenerator.AddExtension(X509Extensions.ExtendedKeyUsage, false, new ExtendedKeyUsage(KeyPurposeID.IdKPServerAuth, KeyPurposeID.IdKPClientAuth)); + s_certGenerator.AddExtension(X509Extensions.ExtendedKeyUsage, false, new ExtendedKeyUsage(KeyPurposeID.id_kp_serverAuth, KeyPurposeID.id_kp_clientAuth)); } else { @@ -373,7 +403,7 @@ private X509CertificateContainer CreateCertificate(bool isAuthority, bool isMach if (isAuthority || certificateCreationSettings.IncludeCrlDistributionPoint) { - var crlDistributionPoints = new DistributionPoint[1] + var crlDistributionPoints = new DistributionPoint[1] { new DistributionPoint( new DistributionPointName( @@ -475,7 +505,7 @@ private X509Crl CreateCrl(X509Certificate signingCertificate) s_crlGenerator.SetThisUpdate(updateTime); //There is no need to update CRL. s_crlGenerator.SetNextUpdate(now.Add(ValidityPeriod)); - s_crlGenerator.SetIssuerDN(PrincipalUtilities.GetSubjectX509Principal(signingCertificate)); + s_crlGenerator.SetIssuerDN(signingCertificate.SubjectDN); s_crlGenerator.AddExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(signingCertificate)); @@ -525,8 +555,8 @@ private static X509Name CreateX509Name(string canonicalName) { X509Name authorityX509Name; - IList authorityKeyIdOrder = new ArrayList(); - IDictionary authorityKeyIdName = new Hashtable(); + IList authorityKeyIdOrder = new List(); + IDictionary authorityKeyIdName = new Dictionary(); authorityKeyIdOrder.Add(X509Name.OU); authorityKeyIdOrder.Add(X509Name.O); diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.cs new file mode 100644 index 00000000000..c80d10bae19 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.cs @@ -0,0 +1,183 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; +using WcfTestCommon; +using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2; +using System.IO; +using System.Net; + +public class CertificateGeneratorLibrary +{ + private const string ClientCertificateSubject = "WCF Client Certificate"; + private const string CertificateIssuer = "DO_NOT_TRUST_WcfBridgeRootCA"; + + private static string s_fqdn = Dns.GetHostEntry("127.0.0.1").HostName; + private static string s_hostname = Dns.GetHostEntry("127.0.0.1").HostName.Split('.')[0]; + private static string s_testserverbase = string.Empty; + private static string s_crlFileLocation = string.Empty; + private static TimeSpan s_validatePeriod; + + private static void RemoveCertificatesFromStore(StoreName storeName, StoreLocation storeLocation) + { + X509Store store = CertificateHelper.GetX509Store(storeName, storeLocation); + Console.WriteLine(" Checking StoreName '{0}'", storeName); + { + store.Open(OpenFlags.ReadWrite | OpenFlags.IncludeArchived); + + foreach (var cert in store.Certificates.Find(X509FindType.FindByIssuerName, CertificateIssuer, false)) + { + Console.Write(" {0}. Subject: '{1}'", cert.Thumbprint, cert.SubjectName.Name); + store.Remove(cert); + Console.WriteLine(" ... removed"); + } + } + Console.WriteLine(); + } + + public static void UninstallAllCerts() + { + RemoveCertificatesFromStore(StoreName.My, StoreLocation.CurrentUser); + RemoveCertificatesFromStore(StoreName.My, StoreLocation.LocalMachine); + + RemoveCertificatesFromStore(StoreName.Root, StoreLocation.LocalMachine); + RemoveCertificatesFromStore(StoreName.Root, StoreLocation.CurrentUser); + + RemoveCertificatesFromStore(StoreName.TrustedPeople, StoreLocation.LocalMachine); + RemoveCertificatesFromStore(StoreName.TrustedPeople, StoreLocation.CurrentUser); + } + + public static int SetupCerts(string testserverbase, TimeSpan validatePeriod, string crlFileLocation) + { + s_testserverbase = testserverbase; + s_validatePeriod = validatePeriod; + s_crlFileLocation = crlFileLocation; + + UninstallAllCerts(); + + CertificateGenerator certificateGenerate = new CertificateGenerator(); + certificateGenerate.CertificatePassword = "test"; + certificateGenerate.CrlServiceUri = s_fqdn; + certificateGenerate.ValidityPeriod = s_validatePeriod; + + if (!string.IsNullOrEmpty(s_testserverbase)) + { + certificateGenerate.CrlUriRelativePath += "/" + s_testserverbase; + } + certificateGenerate.CrlUriRelativePath += "/TestHost.svc/Crl"; + + //Create and install root and server cert + CertificateManager.CreateAndInstallLocalMachineCertificates(certificateGenerate); + + //Create and Install expired cert + CertificateCreationSettings certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - TcpExpiredServerCertResource", + ValidityType = CertificateValidityType.Expired, + ValidityNotBefore = DateTime.UtcNow - TimeSpan.FromDays(4), + ValidityNotAfter = DateTime.UtcNow - TimeSpan.FromDays(2), + //If you specify multiple subjects, the first one becomes the subject, and all of them become Subject Alt Names. + //In this case, the certificate subject is CN=fqdn, OU=..., O=... , and SANs will be fqdn, hostname, localhost + //We do this so that a single WCF service setup can deal with all the possible addresses that a client might use. + Subject = s_fqdn, + SubjectAlternativeNames = new string[] { s_fqdn, s_hostname, "localhost" } + }; + CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); + + + //Create and Install TcpCertificateWithServerAltName + certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - TcpCertificateWithServerAltNameResource", + Subject = "not-real-subject-name", + SubjectAlternativeNames = new string[] { "not-real-subject-name", "not-real-subject-name.example.com", s_fqdn, s_hostname, "localhost" } + }; + CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); + + //TcpCertificateWithSubjectCanonicalNameDomainName + certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - TcpCertificateWithSubjectCanonicalNameDomainNameResource", + Subject = s_hostname, + SubjectAlternativeNames = new string[0], + ValidityType = CertificateValidityType.NonAuthoritativeForMachine + }; + CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); + + //WCF Bridge - TcpCertificateWithSubjectCanonicalNameFqdn + certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - TcpCertificateWithSubjectCanonicalNameFqdnResource", + Subject = s_fqdn, + SubjectAlternativeNames = new string[0], + ValidityType = CertificateValidityType.NonAuthoritativeForMachine + }; + CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); + + //TcpCertificateWithSubjectCanonicalNameLocalhost + certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - TcpCertificateWithSubjectCanonicalNameLocalhostResource", + Subject = "localhost", + SubjectAlternativeNames = new string[0], + ValidityType = CertificateValidityType.NonAuthoritativeForMachine + }; + CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); + + //TcpRevokedServerCert + certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - TcpRevokedServerCertResource", + ValidityType = CertificateValidityType.Revoked, + Subject = s_fqdn, + SubjectAlternativeNames = new string[] { s_fqdn, s_hostname, "localhost" } + }; + CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); + + //TcpInvalidEkuServerCert + certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - TcpInvalidEkuServerCert", + ValidityType = CertificateValidityType.Valid, + Subject = s_fqdn, + SubjectAlternativeNames = new string[] { s_fqdn, s_hostname, "localhost" }, + EKU = new List { Org.BouncyCastle.Asn1.X509.KeyPurposeID.id_kp_clientAuth } + }; + CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); + + //STSMetaData + certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - STSMetaData", + ValidityType = CertificateValidityType.Valid, + Subject = "STSMetaData", + EKU = new List() + }; + CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); + + //Create and install client cert + certificateCreationSettings = new CertificateCreationSettings() + { + FriendlyName = "WCF Bridge - UserCertificateResource", + Subject = "WCF Client Certificate", + }; + X509Certificate2 certificate = certificateGenerate.CreateUserCertificate(certificateCreationSettings).Certificate; + CertificateManager.AddToStoreIfNeeded(StoreName.My, StoreLocation.LocalMachine, certificate); + + //Create CRL and save it + FileInfo file = new FileInfo(s_crlFileLocation); + file.Directory.Create(); + + File.WriteAllBytes(s_crlFileLocation, certificateGenerate.CrlEncoded); + + return 0; + } + + private static void CreateAndInstallMachineCertificate(CertificateGenerator certificateGenerate, CertificateCreationSettings certificateCreationSettings) + { + X509Certificate2 certificate = certificateGenerate.CreateMachineCertificate(certificateCreationSettings).Certificate; + CertificateManager.AddToStoreIfNeeded(StoreName.My, StoreLocation.LocalMachine, certificate); + } +} diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.csproj b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.csproj new file mode 100644 index 00000000000..92870a6959b --- /dev/null +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs new file mode 100644 index 00000000000..62549f50b25 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs @@ -0,0 +1,84 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Cryptography.X509Certificates; +using Infrastructure.Common; + +namespace WcfTestCommon +{ + public static class CertificateHelper + { + public static class CurrentOperatingSystem + { + /// + /// Returns true if current OS is Windows + /// + public static bool IsWindows() => IsOSPlatform(OSPlatform.Windows); + + /// + /// Returns true if current OS is Linux + /// + public static bool IsLinux() => IsOSPlatform(OSPlatform.Linux); + + /// + /// Returns true if current OS is OSX + /// + public static bool IsMacOS() => IsOSPlatform(OSPlatform.OSX); + + /// + /// Returns true if current OS matches OSPlatform + /// + /// OS Platform to check for + public static bool IsOSPlatform(OSPlatform osPlatform) => + RuntimeInformation.IsOSPlatform(osPlatform); + } + + public static X509Store GetX509Store(StoreName storeName, StoreLocation storeLocation) + { + X509Store store = null; + if (CurrentOperatingSystem.IsWindows()) + { + store = new X509Store(storeName, storeLocation); + } + else if (CurrentOperatingSystem.IsLinux()) + { + // Store the certificates in CurrentUser Scope + store = new X509Store(storeName, StoreLocation.CurrentUser); + } + else if (CurrentOperatingSystem.IsMacOS()) + { + // MacOS SafeKeychainHandle + GetMacOSX509Store(); + } + return store; + } + + internal static string OSXCustomKeychainFilePath => Path.Combine(Environment.CurrentDirectory, "wcfLocal.keychain"); + + internal static string OSXCustomKeychainPassword => "WCFKeychainFilePassword"; + + [MethodImpl(MethodImplOptions.NoInlining)] + public static X509Store GetMacOSX509Store() + { + SafeKeychainHandle keychain; + if (!File.Exists(OSXCustomKeychainFilePath)) + { + keychain = SafeKeychainHandle.Create(OSXCustomKeychainFilePath, OSXCustomKeychainPassword); + } + else + { + keychain = SafeKeychainHandle.Open(OSXCustomKeychainFilePath, OSXCustomKeychainPassword); + } + + if (keychain.IsInvalid) + throw new Exception("Unable to open MacOS Keychain"); + + X509Store store = new X509Store(keychain.DangerousGetHandle()); + return store; + } + } +} diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateManager.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateManager.cs similarity index 96% rename from src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateManager.cs rename to src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateManager.cs index 0c9edc14574..6edd5e3dacf 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateManager.cs +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateManager.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; @@ -44,16 +42,14 @@ private static X509Certificate2 CertificateFromThumbprint(X509Store store, strin // Adds the given certificate to the given store unless it is // already present. Returns 'true' if the certificate was added. - public static bool AddToStoreIfNeeded(StoreName storeName, - StoreLocation storeLocation, - X509Certificate2 certificate) + public static bool AddToStoreIfNeeded(StoreName storeName, StoreLocation storeLocation, X509Certificate2 certificate) { X509Store store = null; X509Certificate2 existingCert = null; try { - store = new X509Store(storeName, storeLocation); - + store = CertificateHelper.GetX509Store(storeName, storeLocation); + // We assume Bridge is running elevated store.Open(OpenFlags.ReadWrite); existingCert = CertificateFromThumbprint(store, certificate.Thumbprint); @@ -61,8 +57,8 @@ public static bool AddToStoreIfNeeded(StoreName storeName, { store.Add(certificate); Trace.WriteLine(string.Format("[CertificateManager] Added certificate to store: ")); - Trace.WriteLine(string.Format(" {0} = {1}", "StoreName", storeName)); - Trace.WriteLine(string.Format(" {0} = {1}", "StoreLocation", storeLocation)); + Trace.WriteLine(string.Format(" {0} = {1}", "StoreName", store.Name)); + Trace.WriteLine(string.Format(" {0} = {1}", "StoreLocation", store.Location)); Trace.WriteLine(string.Format(" {0} = {1}", "CN", certificate.SubjectName.Name)); Trace.WriteLine(string.Format(" {0} = {1}", "HasPrivateKey", certificate.HasPrivateKey)); Trace.WriteLine(string.Format(" {0} = {1}", "Thumbprint", certificate.Thumbprint)); diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/SafeKeychainHandle.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/SafeKeychainHandle.cs new file mode 100644 index 00000000000..3f22f6e5f2a --- /dev/null +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/SafeKeychainHandle.cs @@ -0,0 +1,106 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text; +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; + +namespace Infrastructure.Common +{ + // This class facilitates using a private keychain on OSX + public class SafeKeychainHandle : SafeHandle + { + private const string CoreFoundation = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"; + private const string SecurityFramework = "/System/Library/Frameworks/Security.framework/Security"; + + [DllImport(SecurityFramework)] + private static extern int SecKeychainUnlock(SafeKeychainHandle handle, int passphraseLength, byte[] passphraseUtf8, bool usePassword); + + [DllImport(SecurityFramework)] + private static extern int SecKeychainOpen(string path, out SafeKeychainHandle keychain); + + [DllImport(SecurityFramework)] + private static extern int SecKeychainCreate(string pathName, int passphraseLength, byte[] passphraseUtf8, bool promptUser, IntPtr initialAccessNull, out SafeKeychainHandle keychain); + + [DllImport(SecurityFramework)] + private static extern int SecKeychainDelete(SafeKeychainHandle handle); + + [DllImport(CoreFoundation)] + private static extern void CFRelease(IntPtr ptr); + + internal SafeKeychainHandle() + : base(IntPtr.Zero, ownsHandle: true) + { + } + + [MethodImpl(MethodImplOptions.NoInlining)] + protected override bool ReleaseHandle() + { + CFRelease(handle); + SetHandle(IntPtr.Zero); + return true; + } + + public override bool IsInvalid => handle == IntPtr.Zero; + + [MethodImpl(MethodImplOptions.NoInlining)] + public static SafeKeychainHandle Create(string pathName, string passphrase) + { + byte[] utf8Passphrase = Encoding.UTF8.GetBytes(passphrase); + SafeKeychainHandle keychain; + int osStatus = SecKeychainCreate(pathName, utf8Passphrase.Length, utf8Passphrase, false, IntPtr.Zero, out keychain); + + if (osStatus != 0) + { + keychain.Dispose(); + throw new InvalidOperationException($"OSStatus={osStatus}"); + } + + return keychain; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static SafeKeychainHandle Open(string pathName, string passphrase) + { + SafeKeychainHandle keychain; + int osStatus = SecKeychainOpen(pathName, out keychain); + + if (osStatus != 0) + { + keychain.Dispose(); + throw new InvalidOperationException($"OSStatus={osStatus}"); + } + + if(!string.IsNullOrEmpty(passphrase)) + { + byte[] utf8Passphrase = Encoding.UTF8.GetBytes(passphrase); + osStatus = SecKeychainUnlock(keychain, utf8Passphrase.Length, utf8Passphrase, true); + + if (osStatus != 0) + { + keychain.Dispose(); + throw new InvalidOperationException($"OSStatus={osStatus}"); + } + } + + return keychain; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static void Delete(SafeKeychainHandle handle) + { + if (handle.IsInvalid) + return; + + int osStatus = SecKeychainDelete(handle); + handle.Dispose(); + + if (osStatus != 0) + { + throw new InvalidOperationException($"OSStatus={osStatus}"); + } + } + } +} diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/Program.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/Program.cs deleted file mode 100644 index 2fa379d47f0..00000000000 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/Program.cs +++ /dev/null @@ -1,221 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; -using System.Threading.Tasks; -using WcfTestCommon; -using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2; -using X509KeyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags; -using System.IO; -using System.Net; -using System.Configuration; - -namespace CertUtil -{ - internal class Program - { - private const string ClientCertificateSubject = "WCF Client Certificate"; - private const string CertificateIssuer = "DO_NOT_TRUST_WcfBridgeRootCA"; - - private static string s_fqdn = Dns.GetHostEntry("127.0.0.1").HostName; - private static string s_hostname = Dns.GetHostEntry("127.0.0.1").HostName.Split('.')[0]; - private static string s_testserverbase = string.Empty; - private static string s_CrlFileLocation = string.Empty; - private static TimeSpan s_ValidatePeriod; - - private static void RemoveCertificatesFromStore(StoreName storeName, StoreLocation storeLocation) - { - Console.WriteLine(" Checking StoreName '{0}', StoreLocation '{1}'", storeName, storeLocation); - - X509Store store = new X509Store(storeName, storeLocation); - { - store.Open(OpenFlags.ReadWrite | OpenFlags.IncludeArchived); - - foreach (var cert in store.Certificates.Find(X509FindType.FindByIssuerName, CertificateIssuer, false)) - { - Console.Write(" {0}. Subject: '{1}'", cert.Thumbprint, cert.SubjectName.Name); - store.Remove(cert); - Console.Write(" ... removed"); - } - } - Console.WriteLine(); - } - - private static void UninstallAllCerts() - { - RemoveCertificatesFromStore(StoreName.My, StoreLocation.CurrentUser); - RemoveCertificatesFromStore(StoreName.My, StoreLocation.LocalMachine); - - RemoveCertificatesFromStore(StoreName.Root, StoreLocation.LocalMachine); - RemoveCertificatesFromStore(StoreName.Root, StoreLocation.CurrentUser); - - RemoveCertificatesFromStore(StoreName.TrustedPeople, StoreLocation.LocalMachine); - RemoveCertificatesFromStore(StoreName.TrustedPeople, StoreLocation.CurrentUser); - } - - private static void Usage() - { - Console.WriteLine("Supported argument is -Uninstall"); - Console.WriteLine(" -help"); - } - private static int Main(string[] args) - { - ApplyAppSettings(); - - if (args.Length > 0) - { - if (string.Compare(args[0], "-Uninstall", true) == 0) - { - UninstallAllCerts(); - return 0; - } - else if (string.Compare(args[0], "-help", true) == 0) - { - Usage(); - return 0; - } - else - { - Usage(); - return 1; - } - } - - UninstallAllCerts(); - - CertificateGenerator certificateGenerate = new CertificateGenerator(); - certificateGenerate.CertificatePassword = "test"; - certificateGenerate.CrlServiceUri = s_fqdn; - certificateGenerate.ValidityPeriod = s_ValidatePeriod; - - if (!string.IsNullOrEmpty(s_testserverbase)) - { - certificateGenerate.CrlUriRelativePath += "/" + s_testserverbase; - } - certificateGenerate.CrlUriRelativePath += "/TestHost.svc/Crl"; - - //Create and install root and server cert - CertificateManager.CreateAndInstallLocalMachineCertificates(certificateGenerate); - - //Create and Install expired cert - CertificateCreationSettings certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - TcpExpiredServerCertResource", - ValidityType = CertificateValidityType.Expired, - ValidityNotBefore = DateTime.UtcNow - TimeSpan.FromDays(4), - ValidityNotAfter = DateTime.UtcNow - TimeSpan.FromDays(2), - //If you specify multiple subjects, the first one becomes the subject, and all of them become Subject Alt Names. - //In this case, the certificate subject is CN=fqdn, OU=..., O=... , and SANs will be fqdn, hostname, localhost - //We do this so that a single WCF service setup can deal with all the possible addresses that a client might use. - Subject = s_fqdn, - SubjectAlternativeNames = new string[] { s_fqdn, s_hostname, "localhost" } - }; - CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); - - - //Create and Install TcpCertificateWithServerAltName - certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - TcpCertificateWithServerAltNameResource", - Subject = "not-real-subject-name", - SubjectAlternativeNames = new string[] { "not-real-subject-name", "not-real-subject-name.example.com", s_fqdn, s_hostname, "localhost" } - }; - CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); - - //TcpCertificateWithSubjectCanonicalNameDomainName - certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - TcpCertificateWithSubjectCanonicalNameDomainNameResource", - Subject = s_hostname, - SubjectAlternativeNames = new string[0], - ValidityType = CertificateValidityType.NonAuthoritativeForMachine - }; - CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); - - //WCF Bridge - TcpCertificateWithSubjectCanonicalNameFqdn - certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - TcpCertificateWithSubjectCanonicalNameFqdnResource", - Subject = s_fqdn, - SubjectAlternativeNames = new string[0], - ValidityType = CertificateValidityType.NonAuthoritativeForMachine - }; - CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); - - //TcpCertificateWithSubjectCanonicalNameLocalhost - certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - TcpCertificateWithSubjectCanonicalNameLocalhostResource", - Subject = "localhost", - SubjectAlternativeNames = new string[0], - ValidityType = CertificateValidityType.NonAuthoritativeForMachine - }; - CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); - - //TcpRevokedServerCert - certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - TcpRevokedServerCertResource", - ValidityType = CertificateValidityType.Revoked, - Subject = s_fqdn, - SubjectAlternativeNames = new string[] { s_fqdn, s_hostname, "localhost" } - }; - CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); - - //TcpInvalidEkuServerCert - certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - TcpInvalidEkuServerCert", - ValidityType = CertificateValidityType.Valid, - Subject = s_fqdn, - SubjectAlternativeNames = new string[] { s_fqdn, s_hostname, "localhost" }, - EKU = new List { Org.BouncyCastle.Asn1.X509.KeyPurposeID.IdKPClientAuth } - }; - CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); - - //STSMetaData - certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - STSMetaData", - ValidityType = CertificateValidityType.Valid, - Subject = "STSMetaData", - EKU = new List() - }; - CreateAndInstallMachineCertificate(certificateGenerate, certificateCreationSettings); - - //Create and install client cert - certificateCreationSettings = new CertificateCreationSettings() - { - FriendlyName = "WCF Bridge - UserCertificateResource", - Subject = "WCF Client Certificate", - }; - X509Certificate2 certificate = certificateGenerate.CreateUserCertificate(certificateCreationSettings).Certificate; - CertificateManager.AddToStoreIfNeeded(StoreName.My, StoreLocation.LocalMachine, certificate); - - //Create CRL and save it - File.WriteAllBytes(s_CrlFileLocation, certificateGenerate.CrlEncoded); - - return 0; - } - - private static void ApplyAppSettings() - { - var appSettings = ConfigurationManager.AppSettings; - s_testserverbase = appSettings["testserverbase"] ?? string.Empty; - s_ValidatePeriod = TimeSpan.FromDays(int.Parse(appSettings["CertExpirationInDay"])); - s_CrlFileLocation = appSettings["CrlFileLocation"]; - } - - private static void CreateAndInstallMachineCertificate(CertificateGenerator certificateGenerate, CertificateCreationSettings certificateCreationSettings) - { - X509Certificate2 certificate = certificateGenerate.CreateMachineCertificate(certificateCreationSettings).Certificate; - CertificateManager.AddToStoreIfNeeded(StoreName.My, StoreLocation.LocalMachine, certificate); - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ActivationServiceHostFactory.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ActivationServiceHostFactory.cs index 9998bcffc3d..3b3e0f7bd1f 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ActivationServiceHostFactory.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ActivationServiceHostFactory.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System; using System.ServiceModel; using System.ServiceModel.Activation; @@ -16,3 +17,4 @@ public override ServiceHostBase CreateServiceHost(string constructorString, Uri[ } } } +#endif diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/AsyncResult.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/AsyncResult.cs deleted file mode 100644 index 428961d250c..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/AsyncResult.cs +++ /dev/null @@ -1,238 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Diagnostics; -using System.Threading; - -namespace Microsoft.Samples.MessageInterceptor -{ - /// - /// A generic base class for IAsyncResult implementations - /// that wraps a ManualResetEvent. - /// - internal abstract class AsyncResult : IAsyncResult - { - private AsyncCallback _callback; - private object _state; - private bool _completedSynchronously; - private bool _endCalled; - private Exception _exception; - private bool _isCompleted; - private ManualResetEvent _manualResetEvent; - private object _thisLock; - - protected AsyncResult(AsyncCallback callback, object state) - { - _callback = callback; - _state = state; - _thisLock = new object(); - } - - public object AsyncState - { - get - { - return _state; - } - } - - public WaitHandle AsyncWaitHandle - { - get - { - if (_manualResetEvent != null) - { - return _manualResetEvent; - } - - lock (ThisLock) - { - if (_manualResetEvent == null) - { - _manualResetEvent = new ManualResetEvent(_isCompleted); - } - } - - return _manualResetEvent; - } - } - - public bool CompletedSynchronously - { - get - { - return _completedSynchronously; - } - } - - public bool IsCompleted - { - get - { - return _isCompleted; - } - } - - private object ThisLock - { - get - { - return _thisLock; - } - } - - // Call this version of complete when your asynchronous operation is complete. This will update the state - // of the operation and notify the callback. - protected void Complete(bool completedSynchronously) - { - if (_isCompleted) - { - // It is a bug to call Complete twice. - throw new InvalidOperationException("Cannot call Complete twice"); - } - - _completedSynchronously = completedSynchronously; - - if (completedSynchronously) - { - // If we completedSynchronously, then there is no chance that the manualResetEvent was created so - // we do not need to worry about a race condition. - Debug.Assert(_manualResetEvent == null, "No ManualResetEvent should be created for a synchronous AsyncResult."); - _isCompleted = true; - } - else - { - lock (ThisLock) - { - _isCompleted = true; - if (_manualResetEvent != null) - { - _manualResetEvent.Set(); - } - } - } - - // If the callback throws, there is a bug in the callback implementation - if (_callback != null) - { - _callback(this); - } - } - - // Call this version of complete if you raise an exception during processing. In addition to notifying - // the callback, it will capture the exception and store it to be thrown during AsyncResult.End. - protected void Complete(bool completedSynchronously, Exception exception) - { - _exception = exception; - Complete(completedSynchronously); - } - - // End should be called when the End function for the asynchronous operation is complete. It - // ensures the asynchronous operation is complete, and does some common validation. - protected static TAsyncResult End(IAsyncResult result) - where TAsyncResult : AsyncResult - { - if (result == null) - { - throw new ArgumentNullException("result"); - } - - TAsyncResult asyncResult = result as TAsyncResult; - - if (asyncResult == null) - { - throw new ArgumentException("Invalid async result.", "result"); - } - - if (asyncResult._endCalled) - { - throw new InvalidOperationException("Async object already ended."); - } - - asyncResult._endCalled = true; - - if (!asyncResult._isCompleted) - { - asyncResult.AsyncWaitHandle.WaitOne(); - } - - if (asyncResult._manualResetEvent != null) - { - asyncResult._manualResetEvent.Close(); - } - - if (asyncResult._exception != null) - { - throw asyncResult._exception; - } - - return asyncResult; - } - } - - //An AsyncResult that completes as soon as it is instantiated. - internal class CompletedAsyncResult : AsyncResult - { - public CompletedAsyncResult(AsyncCallback callback, object state) - : base(callback, state) - { - Complete(true); - } - - public static void End(IAsyncResult result) - { - AsyncResult.End(result); - } - } - - //A strongly typed AsyncResult - internal abstract class TypedAsyncResult : AsyncResult - { - private T _data; - - protected TypedAsyncResult(AsyncCallback callback, object state) - : base(callback, state) - { - } - - public T Data - { - get { return _data; } - } - - protected void Complete(T data, bool completedSynchronously) - { - _data = data; - Complete(completedSynchronously); - } - - public static T End(IAsyncResult result) - { - TypedAsyncResult typedResult = AsyncResult.End>(result); - return typedResult.Data; - } - } - - //A strongly typed AsyncResult that completes as soon as it is instantiated. - internal class TypedCompletedAsyncResult : TypedAsyncResult - { - public TypedCompletedAsyncResult(T data, AsyncCallback callback, object state) - : base(callback, state) - { - Complete(data, true); - } - - public new static T End(IAsyncResult result) - { - TypedCompletedAsyncResult completedResult = result as TypedCompletedAsyncResult; - if (completedResult == null) - { - throw new ArgumentException("Invalid async result.", "result"); - } - - return TypedAsyncResult.End(completedResult); - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/BasicServiceAuthorizationManager.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/BasicServiceAuthorizationManager.cs index b339abf8366..3c47af44aa2 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/BasicServiceAuthorizationManager.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/BasicServiceAuthorizationManager.cs @@ -2,15 +2,22 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Description; +using CoreWCF.Dispatcher; +#else using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Net; -using System.Security.Principal; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; +#endif +using System.Collections.ObjectModel; +using System.Net; +using System.Security.Principal; using System.Text; namespace WcfService @@ -45,6 +52,7 @@ private bool Authorized(BasicAuthenticationState basicState, OperationContext op return true; } + [Obsolete] public override bool CheckAccess(OperationContext operationContext, ref Message message) { var basicState = new BasicAuthenticationState(operationContext, GetRealm(ref message)); @@ -122,18 +130,15 @@ private struct BasicAuthenticationState private readonly string _realm; private string _username; private string _password; - private bool? _authorized; public BasicAuthenticationState(OperationContext operationContext, string realm) { _operationContext = operationContext; _realm = realm; _username = _password = string.Empty; - _authorized = new bool?(); _authorizationHeader = GetAuthorizationHeader(operationContext); if (_authorizationHeader.Length < BasicAuthenticationMechanismLength) { - _authorized = false; return; } @@ -143,7 +148,6 @@ public BasicAuthenticationState(OperationContext operationContext, string realm) int colonPos = authDecoded.IndexOf(':'); if(colonPos <= 0) { - _authorized = false; return; } _username = authDecoded.Substring(0, colonPos); diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ChainedAsyncResult.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ChainedAsyncResult.cs deleted file mode 100644 index 2883667fc5c..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ChainedAsyncResult.cs +++ /dev/null @@ -1,116 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; - -namespace Microsoft.Samples.MessageInterceptor -{ - internal delegate IAsyncResult ChainedBeginHandler(TimeSpan timeout, AsyncCallback asyncCallback, object state); - internal delegate void ChainedEndHandler(IAsyncResult result); - - internal class ChainedAsyncResult : AsyncResult - { - private ChainedBeginHandler _begin2; - private ChainedEndHandler _end1; - private ChainedEndHandler _end2; - private TimeoutHelper _timeoutHelper; - private static AsyncCallback s_begin1Callback = new AsyncCallback(Begin1Callback); - private static AsyncCallback s_begin2Callback = new AsyncCallback(Begin2Callback); - - protected ChainedAsyncResult(TimeSpan timeout, AsyncCallback callback, object state) - : base(callback, state) - { - _timeoutHelper = new TimeoutHelper(timeout); - } - - public ChainedAsyncResult(TimeSpan timeout, AsyncCallback callback, object state, ChainedBeginHandler begin1, ChainedEndHandler end1, ChainedBeginHandler begin2, ChainedEndHandler end2) - : base(callback, state) - { - _timeoutHelper = new TimeoutHelper(timeout); - Begin(begin1, end1, begin2, end2); - } - - protected void Begin(ChainedBeginHandler begin1, ChainedEndHandler end1, ChainedBeginHandler begin2, ChainedEndHandler end2) - { - _end1 = end1; - _begin2 = begin2; - _end2 = end2; - - IAsyncResult result = begin1(_timeoutHelper.RemainingTime(), s_begin1Callback, this); - if (!result.CompletedSynchronously) - return; - - if (Begin1Completed(result)) - { - this.Complete(true); - } - } - - private static void Begin1Callback(IAsyncResult result) - { - if (result.CompletedSynchronously) - return; - - ChainedAsyncResult thisPtr = (ChainedAsyncResult)result.AsyncState; - - bool completeSelf = false; - Exception completeException = null; - - try - { - completeSelf = thisPtr.Begin1Completed(result); - } - catch (Exception exception) - { - completeSelf = true; - completeException = exception; - } - - if (completeSelf) - { - thisPtr.Complete(false, completeException); - } - } - - private bool Begin1Completed(IAsyncResult result) - { - _end1(result); - - result = _begin2(_timeoutHelper.RemainingTime(), s_begin2Callback, this); - if (!result.CompletedSynchronously) - { - return false; - } - - _end2(result); - return true; - } - - private static void Begin2Callback(IAsyncResult result) - { - if (result.CompletedSynchronously) - return; - - ChainedAsyncResult thisPtr = (ChainedAsyncResult)result.AsyncState; - - Exception completeException = null; - - try - { - thisPtr._end2(result); - } - catch (Exception exception) - { - completeException = exception; - } - - thisPtr.Complete(false, completeException); - } - - public static void End(IAsyncResult result) - { - AsyncResult.End(result); - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ChannelMessageInterceptor.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ChannelMessageInterceptor.cs deleted file mode 100644 index d50cf5a1386..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ChannelMessageInterceptor.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.ServiceModel.Channels; -using System.ServiceModel.Description; - -namespace Microsoft.Samples.MessageInterceptor -{ - public abstract class ChannelMessageInterceptor - { - public virtual void OnSend(ref Message message) { } - public virtual void OnReceive(ref Message message) { } - - public virtual void OnExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { } - - public virtual void OnImportPolicy(MetadataImporter importer, PolicyConversionContext context) { } - - public abstract ChannelMessageInterceptor Clone(); - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ComplexCompositeType.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ComplexCompositeType.cs index 65fa76b62ba..c3b4a03aa13 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ComplexCompositeType.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ComplexCompositeType.cs @@ -2,8 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System; using System.Runtime.Serialization; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CompositeType.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CompositeType.cs index 677f0944c36..fb3497d9aee 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CompositeType.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CompositeType.cs @@ -2,9 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.Runtime.Serialization; using System.ServiceModel; +#endif using System.Xml; using System.Xml.Serialization; diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs new file mode 100644 index 00000000000..518a27ca6ae --- /dev/null +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#if NET + +using CoreWCF; +using CoreWCF.Channels; + +namespace WcfService +{ + //public enum BasicHttpsSecurityMode + //{ + // // + // // Summary: + // // The Transport security mode. + // Transport, + // // + // // Summary: + // // The TransportWithMessageCredential security mode. + // TransportWithMessageCredential + //} + + // Cast BasicHttpsSecurityMode (WCF) to BasicHttpSecurityMode (CoreWCF) + internal enum BasicHttpsSecurityMode + { + None, + Transport, + Message, + TransportWithMessageCredential, + TransportCredentialOnly + } + + internal class BasicHttpsBinding : BasicHttpBinding + { + public BasicHttpsBinding() : base((BasicHttpSecurityMode)BasicHttpsSecurityMode.Transport) + { + } + + public BasicHttpsBinding(BasicHttpsSecurityMode securityMode) : base((BasicHttpSecurityMode)securityMode) + { + } + } +} +#endif diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/ServiceHostHelper.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/ServiceHostHelper.cs new file mode 100644 index 00000000000..f0dfdd0af20 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/ServiceHostHelper.cs @@ -0,0 +1,92 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#if NET +using System.Diagnostics; + +namespace WcfService +{ + public class ServiceHostHelper + { + public static async Task PingAsync(string url) + { + Console.WriteLine("Ping service host..."); + using HttpClient httpClient = new HttpClient(); + + for (int i = 0; i < 10; i++) + { + try + { + using HttpResponseMessage response = await httpClient.GetAsync(url); + if (response.IsSuccessStatusCode) + { + Console.WriteLine("Ping succeed..."); + httpClient.Dispose(); + return true; + } + else + { + Console.WriteLine($"Ping failed... retrying after 10 seconds. {response.ReasonPhrase}"); + } + } + catch (Exception ex) + { + Console.WriteLine($"Ping failed... retrying after 10 seconds. {ex.Message}"); + } + await Task.Delay(10000); + } + + Console.WriteLine("Ping failed... Exiting.."); + httpClient.Dispose(); + return false; + } + + public static async Task ServiceBootstrap() + { + string processArgs = ""; + if (Process.GetCurrentProcess().ProcessName == "dotnet") + { + processArgs = "exec --roll-forward Major " + String.Join(" ", Environment.GetCommandLineArgs().SkipLast(1)); + } + + var process = new Process() + { + StartInfo = { + FileName = Environment.ProcessPath, + Arguments = processArgs, + WindowStyle = ProcessWindowStyle.Normal, + WorkingDirectory = Environment.CurrentDirectory, + RedirectStandardOutput = false, + RedirectStandardInput = false, + UseShellExecute = false + }, + EnableRaisingEvents = false + }; + + process.Start(); + + Console.WriteLine($"Starting process in the background: {Path.GetFileName(process.ProcessName)}, ID: {process.Id}."); + + // Ping to make sure the service is started + bool result = await PingAsync("http://localhost:8081/TestHost.svc/Ping"); + if (result) + { + Environment.Exit(0); + } + Environment.Exit(1); + } + + public static Enum ToServiceSchema(string CoreWcfScheme) => CoreWcfScheme switch + { + "http" => ServiceSchema.HTTP, + "https" => ServiceSchema.HTTPS, + "net.tcp" => ServiceSchema.NETTCP, + "net.pipe" => ServiceSchema.NETPIPE, + "ws" => ServiceSchema.WS, + "wss" => ServiceSchema.WSS, + _ => throw new ArgumentOutOfRangeException(nameof(CoreWcfScheme), $"Not expected CoreWcfScheme value: {CoreWcfScheme}"), + }; + } +} +#endif diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/TestHostServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/TestHostServiceHost.cs new file mode 100644 index 00000000000..9638b67aea4 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/TestHostServiceHost.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#if NET +using CoreWCF; +using CoreWCF.Channels; + +namespace WcfService +{ + //Start the crlUrl service as the client use it to ensure all services have been started + [TestServiceDefinition(BasePath = "", Schema = ServiceSchema.HTTP)] + public class TestHostServiceHost : TestServiceHostBase + { + protected override string Address { get { return "TestHost.svc"; } } + + protected override Binding GetBinding() + { + return GetWebHttpBinding(); + } + + private Binding GetWebHttpBinding() + { + var binding = new WebHttpBinding(); + return binding; + } + + public TestHostServiceHost(params Uri[] baseAddresses) + : base(typeof(TestHost), baseAddresses) + { + } + } +} +#endif diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/WcfServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/WcfServiceHost.cs new file mode 100644 index 00000000000..3df37d57284 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/WcfServiceHost.cs @@ -0,0 +1,58 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Description; + +namespace WcfService +{ + public class ServiceHost + { + private ServiceHostBase _serviceHostBase = null; + private readonly Type _serviceType; + private readonly List _endpoints = new List(); + + public ServiceHost(Type serviceType, params Uri[] baseAddresses) + { + _serviceType = serviceType ?? throw new ArgumentNullException(nameof(serviceType)); + } + + public void AddServiceEndpoint(Type implementedContract, Binding binding, string address) + { + _endpoints.Add(new Endpoint + { + ContractType = implementedContract, + Binding = binding, + Address = address + }); + } + + protected virtual void ApplyConfiguration() { } + + public void ApplyConfig(ServiceHostBase serviceHostBase) + { + _serviceHostBase = serviceHostBase; + ApplyConfiguration(); + _serviceHostBase = null; + } + + public List Endpoints => _endpoints; + + public class Endpoint + { + public Type ContractType { get; set; } + public Binding Binding { get; set; } + public string Address { get; set; } + } + + public Type ServiceType => _serviceHostBase != null ? _serviceHostBase.Description.ServiceType : _serviceType; + + public ServiceCredentials Credentials => _serviceHostBase != null ? _serviceHostBase.Credentials : new ServiceCredentials(); + + public ServiceDescription Description => _serviceHostBase != null ? _serviceHostBase.Description : new ServiceDescription(); + } +} +#endif diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DataContractResolverService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DataContractResolverService.cs index 85242d03ecb..000a149cf29 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DataContractResolverService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DataContractResolverService.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.Collections.Generic; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DigestServiceAuthorizationManager.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DigestServiceAuthorizationManager.cs index c0fa086bf0a..a73bdb2ee98 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DigestServiceAuthorizationManager.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DigestServiceAuthorizationManager.cs @@ -2,16 +2,23 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Description; +using CoreWCF.Dispatcher; +#else using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Net; -using System.Security.Cryptography; -using System.Security.Principal; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; +#endif +using System.Collections.ObjectModel; +using System.Net; +using System.Security.Cryptography; +using System.Security.Principal; using System.Text; namespace WcfService @@ -47,6 +54,7 @@ private bool Authorized(DigestAuthenticationState digestState, OperationContext return true; } + [Obsolete] public override bool CheckAccess(OperationContext operationContext, ref Message message) { var contractName = operationContext.EndpointDispatcher.ContractName; diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FaultDetail.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FaultDetail.cs index 09572e5fb0d..0e20623fe1d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FaultDetail.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FaultDetail.cs @@ -2,7 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System.Runtime.Serialization; +#endif using System.Xml.Serialization; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FaultDetail2.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FaultDetail2.cs index 8281b56faa3..f8b72348bcc 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FaultDetail2.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FaultDetail2.cs @@ -1,7 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if !NET using System.Runtime.Serialization; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FlowControlledStream.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FlowControlledStream.cs index 583563e1c6b..8fa7db80c96 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FlowControlledStream.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/FlowControlledStream.cs @@ -2,9 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System; using System.IO; using System.Threading; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IDataResolverService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IDataResolverService.cs index 198942d2413..55de91f097d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IDataResolverService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IDataResolverService.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.Collections.Generic; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IPushCallback.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IPushCallback.cs index 2951c10d2b8..4ed7c9486b0 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IPushCallback.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IPushCallback.cs @@ -2,9 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.Collections.Generic; using System.IO; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IService1.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IService1.cs index dde286f74c0..dbfb6394708 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IService1.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IService1.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ISessionTests.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ISessionTests.cs index 32069afc997..1e3bd0611b2 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ISessionTests.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ISessionTests.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.Runtime.Serialization; using System.ServiceModel; +#endif namespace WcfService { @@ -73,4 +77,4 @@ public interface ISessionTestsDuplexCallback // note IsTerminating = false while the client callback has IsTerminating = true [OperationContract(IsInitiating = true, IsTerminating = false)] int ClientSideOnlyTerminatingClientCallback(int callsToNonTerminatingMethodToMake, int callsToTerminatingMethodToMake); -} \ No newline at end of file +} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IUnderstoodHeaders.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IUnderstoodHeaders.cs index eea9f29a6a4..fe8523c33b4 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IUnderstoodHeaders.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IUnderstoodHeaders.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IVerifyWebSockets.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IVerifyWebSockets.cs index b0751f9d3a3..f69bab95dec 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IVerifyWebSockets.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IVerifyWebSockets.cs @@ -2,8 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWSDuplexService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWSDuplexService.cs index 9fa7f8c4856..d34b29c1b8d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWSDuplexService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWSDuplexService.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.IO; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWSRequestReplyService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWSRequestReplyService.cs index 1ee51d941af..12c9952d42d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWSRequestReplyService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWSRequestReplyService.cs @@ -2,10 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.Collections.Generic; using System.IO; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfChannelExtensibilityService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfChannelExtensibilityService.cs index 5ee68858478..927e2b28333 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfChannelExtensibilityService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfChannelExtensibilityService.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfCustomUserNameService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfCustomUserNameService.cs index 921f21d2c13..b836da6b84a 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfCustomUserNameService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfCustomUserNameService.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfDecompService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfDecompService.cs index fd94a459de0..05f10ec43db 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfDecompService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfDecompService.cs @@ -2,11 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.Collections.Generic; using System.IO; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfDuplexService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfDuplexService.cs index df6d45397d5..c4808bfc691 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfDuplexService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfDuplexService.cs @@ -2,9 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; using System.Threading.Tasks; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfReliableService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfReliableService.cs index 0f9537bec52..1b5e29358e8 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfReliableService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfReliableService.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfRestartService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfRestartService.cs index d8537c209ba..6c60338b759 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfRestartService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfRestartService.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfService.4.4.0.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfService.4.4.0.cs index a825ac85d64..0c998dd7ed7 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfService.4.4.0.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfService.4.4.0.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfService.cs index d8abb1bf1d6..c92f334d6b3 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfService.cs @@ -2,11 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.IO; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { @@ -117,7 +122,7 @@ public interface IWcfService Stream EchoStream(Stream stream); [OperationContract(Action = "http://tempuri.org/IWcfService/EchoMessageParameter")] - [return: System.ServiceModel.MessageParameterAttribute(Name = "result")] + [return: MessageParameterAttribute(Name = "result")] string EchoMessageParameter(string name); [OperationContract(Action = "http://tempuri.org/IWcfService/EchoItems")] diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfSoapService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfSoapService.cs index 2af379bfe81..3eb87a46e38 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfSoapService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IWcfSoapService.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IXmlSFAttribute.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IXmlSFAttribute.cs index 2ea80e137d2..7b0d002c4c2 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IXmlSFAttribute.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IXmlSFAttribute.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IXmlSerFormatAttrServices.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IXmlSerFormatAttrServices.cs index a2e5542179b..27d483b1d2d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IXmlSerFormatAttrServices.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/IXmlSerFormatAttrServices.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingBindingElement.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingBindingElement.cs deleted file mode 100644 index ddb5822682a..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingBindingElement.cs +++ /dev/null @@ -1,98 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ServiceModel.Channels; -using System.ServiceModel.Description; - -namespace Microsoft.Samples.MessageInterceptor -{ - public class InterceptingBindingElement - : BindingElement - , IPolicyExportExtension - { - private ChannelMessageInterceptor _interceptor; - - public InterceptingBindingElement(ChannelMessageInterceptor interceptor) - { - _interceptor = interceptor; - } - - protected InterceptingBindingElement(InterceptingBindingElement other) - : base(other) - { - _interceptor = other.Interceptor; - } - - public ChannelMessageInterceptor Interceptor - { - get - { - if (_interceptor != null) - { - return _interceptor.Clone(); - } - else - { - return new NullMessageInterceptor(); - } - } - } - - public override BindingElement Clone() - { - return new InterceptingBindingElement(this); - } - - public override bool CanBuildChannelFactory(BindingContext context) - { - return context.CanBuildInnerChannelFactory(); - } - - public override bool CanBuildChannelListener(BindingContext context) - { - return context.CanBuildInnerChannelListener(); - } - - public override IChannelFactory BuildChannelFactory(BindingContext context) - { - return new InterceptingChannelFactory(this.Interceptor, context); - } - - public override IChannelListener BuildChannelListener(BindingContext context) - { - return new InterceptingChannelListener(this.Interceptor, context); - } - - public override T GetProperty(BindingContext context) - { - if (typeof(T) == typeof(ChannelMessageInterceptor)) - { - return (T)(object)this.Interceptor; - } - - return context.GetInnerProperty(); - } - - void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) - { - if (context == null) - { - throw new ArgumentNullException("context"); - } - - _interceptor.OnExportPolicy(exporter, context); - } - - - private class NullMessageInterceptor : ChannelMessageInterceptor - { - public override ChannelMessageInterceptor Clone() - { - return new NullMessageInterceptor(); - } - } - } -} - diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingBindingElementImporter.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingBindingElementImporter.cs deleted file mode 100644 index de73d54ab9f..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingBindingElementImporter.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.ServiceModel.Description; - -namespace Microsoft.Samples.MessageInterceptor -{ - public abstract class InterceptingBindingElementImporter : IPolicyImportExtension - { - void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context) - { - ChannelMessageInterceptor messageInterceptor = CreateMessageInterceptor(); - messageInterceptor.OnImportPolicy(importer, context); - } - - protected abstract ChannelMessageInterceptor CreateMessageInterceptor(); - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelBase.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelBase.cs deleted file mode 100644 index c20dc3fec53..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelBase.cs +++ /dev/null @@ -1,96 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ServiceModel.Channels; - -namespace Microsoft.Samples.MessageInterceptor -{ - /// - /// Base channel class that uses an ChannelMessageInterceptor - /// - internal class InterceptingChannelBase : ChannelBase - where TChannel : class, IChannel - { - private ChannelMessageInterceptor _interceptor; - private TChannel _innerChannel; - - protected InterceptingChannelBase( - ChannelManagerBase manager, ChannelMessageInterceptor interceptor, TChannel innerChannel) - : base(manager) - { - if (innerChannel == null) - { - throw new ArgumentException("InterceptingChannelBase requires a non-null inner channel.", "innerChannel"); - } - - _interceptor = interceptor; - _innerChannel = innerChannel; - } - - protected TChannel InnerChannel - { - get - { - return _innerChannel; - } - } - - public override T GetProperty() - { - T baseProperty = base.GetProperty(); - if (baseProperty != null) - { - return baseProperty; - } - - return this.InnerChannel.GetProperty(); - } - - protected override void OnAbort() - { - _innerChannel.Abort(); - } - - protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) - { - return _innerChannel.BeginClose(timeout, callback, state); - } - - protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) - { - return _innerChannel.BeginOpen(timeout, callback, state); - } - - protected override void OnClose(TimeSpan timeout) - { - _innerChannel.Close(timeout); - } - - protected override void OnEndClose(IAsyncResult result) - { - _innerChannel.EndClose(result); - } - - protected override void OnEndOpen(IAsyncResult result) - { - _innerChannel.EndOpen(result); - } - - protected override void OnOpen(TimeSpan timeout) - { - _innerChannel.Open(timeout); - } - - protected void OnReceive(ref Message message) - { - _interceptor.OnReceive(ref message); - } - - protected void OnSend(ref Message message) - { - _interceptor.OnSend(ref message); - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelFactory.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelFactory.cs deleted file mode 100644 index 036a3468534..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelFactory.cs +++ /dev/null @@ -1,392 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ServiceModel; -using System.ServiceModel.Channels; - -namespace Microsoft.Samples.MessageInterceptor -{ - /// - /// ChannelFactory that performs message Interception - /// - internal class InterceptingChannelFactory - : ChannelFactoryBase - { - private ChannelMessageInterceptor _interceptor; - private IChannelFactory _innerChannelFactory; - - public InterceptingChannelFactory(ChannelMessageInterceptor interceptor, BindingContext context) - { - _interceptor = interceptor; - _innerChannelFactory = context.BuildInnerChannelFactory(); - if (_innerChannelFactory == null) - { - throw new InvalidOperationException("InterceptingChannelFactory requires an inner IChannelFactory."); - } - } - - public ChannelMessageInterceptor Interceptor - { - get { return _interceptor; } - } - - public override T GetProperty() - { - T baseProperty = base.GetProperty(); - if (baseProperty != null) - { - return baseProperty; - } - - return _innerChannelFactory.GetProperty(); - } - - protected override void OnOpen(TimeSpan timeout) - { - _innerChannelFactory.Open(timeout); - } - - protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) - { - return _innerChannelFactory.BeginOpen(timeout, callback, state); - } - - protected override void OnEndOpen(IAsyncResult result) - { - _innerChannelFactory.EndOpen(result); - } - - protected override void OnAbort() - { - base.OnAbort(); - _innerChannelFactory.Abort(); - } - - protected override void OnClose(TimeSpan timeout) - { - TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); - base.OnClose(timeoutHelper.RemainingTime()); - _innerChannelFactory.Close(timeoutHelper.RemainingTime()); - } - - protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) - { - return new ChainedAsyncResult(timeout, callback, state, base.OnBeginClose, base.OnEndClose, _innerChannelFactory.BeginClose, _innerChannelFactory.EndClose); - } - - protected override void OnEndClose(IAsyncResult result) - { - ChainedAsyncResult.End(result); - } - - protected override TChannel OnCreateChannel(EndpointAddress to, Uri via) - { - TChannel innerChannel = _innerChannelFactory.CreateChannel(to, via); - if (typeof(TChannel) == typeof(IOutputChannel)) - { - return (TChannel)(object)new InterceptingOutputChannel(this, (IOutputChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IRequestChannel)) - { - return (TChannel)(object)new InterceptingRequestChannel(this, (IRequestChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IDuplexChannel)) - { - return (TChannel)(object)new InterceptingDuplexChannel(this, Interceptor, (IDuplexChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IOutputSessionChannel)) - { - return (TChannel)(object)new InterceptingOutputSessionChannel(this, (IOutputSessionChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IRequestSessionChannel)) - { - return (TChannel)(object)new InterceptingRequestSessionChannel(this, - (IRequestSessionChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IDuplexSessionChannel)) - { - return (TChannel)(object)new InterceptingDuplexSessionChannel(this, Interceptor, (IDuplexSessionChannel)innerChannel); - } - - throw new InvalidOperationException(); - } - - private class InterceptingOutputChannel - : InterceptingChannelBase, IOutputChannel - { - public InterceptingOutputChannel(InterceptingChannelFactory factory, IOutputChannel innerChannel) - : base(factory, factory.Interceptor, innerChannel) - { - // empty - } - - public EndpointAddress RemoteAddress - { - get - { - return this.InnerChannel.RemoteAddress; - } - } - - public Uri Via - { - get - { - return this.InnerChannel.Via; - } - } - - public IAsyncResult BeginSend(Message message, AsyncCallback callback, object state) - { - return BeginSend(message, DefaultSendTimeout, callback, state); - } - - public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state) - { - this.OnSend(ref message); - return new SendAsyncResult(this, message, timeout, callback, state); - } - - public void EndSend(IAsyncResult result) - { - SendAsyncResult.End(result); - } - - public void Send(Message message) - { - Send(message, DefaultSendTimeout); - } - - public void Send(Message message, TimeSpan timeout) - { - base.OnSend(ref message); - - if (message != null) - { - this.InnerChannel.Send(message, timeout); - } - } - - private class SendAsyncResult : AsyncResult - { - private IOutputChannel _channel; - private AsyncCallback _sendCallback = new AsyncCallback(OnSend); - - public SendAsyncResult(IOutputChannel channel, Message message, TimeSpan timeout, AsyncCallback callback, object state) - : base(callback, state) - { - if (message != null) - { - _channel = channel; - - IAsyncResult sendResult = channel.BeginSend(message, timeout, _sendCallback, this); - if (!sendResult.CompletedSynchronously) - { - return; - } - - CompleteSend(sendResult); - } - - base.Complete(true); - } - - private void CompleteSend(IAsyncResult result) - { - _channel.EndSend(result); - } - - private static void OnSend(IAsyncResult result) - { - if (result.CompletedSynchronously) - { - return; - } - - SendAsyncResult thisPtr = (SendAsyncResult)result.AsyncState; - Exception completionException = null; - - try - { - thisPtr.CompleteSend(result); - } - catch (Exception e) - { - completionException = e; - } - - thisPtr.Complete(false, completionException); - } - - public static void End(IAsyncResult result) - { - AsyncResult.End(result); - } - } - } - - private class InterceptingRequestChannel - : InterceptingChannelBase, IRequestChannel - { - public InterceptingRequestChannel( - InterceptingChannelFactory factory, IRequestChannel innerChannel) - : base(factory, factory.Interceptor, innerChannel) - { - // empty - } - - public EndpointAddress RemoteAddress - { - get - { - return this.InnerChannel.RemoteAddress; - } - } - - public Uri Via - { - get - { - return this.InnerChannel.Via; - } - } - - public IAsyncResult BeginRequest(Message message, AsyncCallback callback, object state) - { - return BeginRequest(message, this.DefaultSendTimeout, callback, state); - } - - public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state) - { - base.OnSend(ref message); - return new RequestAsyncResult(this, message, timeout, callback, state); - } - - public Message EndRequest(IAsyncResult result) - { - Message reply = RequestAsyncResult.End(result); - this.OnReceive(ref reply); - return reply; - } - - public Message Request(Message message) - { - return Request(message, this.DefaultSendTimeout); - } - - public Message Request(Message message, TimeSpan timeout) - { - this.OnSend(ref message); - Message reply = null; - if (message != null) - { - reply = this.InnerChannel.Request(message); - } - - this.OnReceive(ref reply); - return reply; - } - - private class RequestAsyncResult : AsyncResult - { - private Message _replyMessage; - private InterceptingRequestChannel _channel; - private AsyncCallback _requestCallback = new AsyncCallback(OnRequest); - - public RequestAsyncResult(InterceptingRequestChannel channel, Message message, TimeSpan timeout, AsyncCallback callback, object state) - : base(callback, state) - { - if (message != null) - { - _channel = channel; - - IAsyncResult requestResult = channel.InnerChannel.BeginRequest(message, timeout, _requestCallback, this); - if (!requestResult.CompletedSynchronously) - { - return; - } - - CompleteRequest(requestResult); - } - - base.Complete(true); - } - - private void CompleteRequest(IAsyncResult result) - { - _replyMessage = _channel.InnerChannel.EndRequest(result); - } - - private static void OnRequest(IAsyncResult result) - { - if (result.CompletedSynchronously) - { - return; - } - - RequestAsyncResult thisPtr = (RequestAsyncResult)result.AsyncState; - Exception completionException = null; - - try - { - thisPtr.CompleteRequest(result); - } - catch (Exception e) - { - completionException = e; - } - - thisPtr.Complete(false, completionException); - } - - public static Message End(IAsyncResult result) - { - RequestAsyncResult thisPtr = AsyncResult.End(result); - return thisPtr._replyMessage; - } - } - } - - private class InterceptingOutputSessionChannel : InterceptingOutputChannel, IOutputSessionChannel - { - private IOutputSessionChannel _innerSessionChannel; - - public InterceptingOutputSessionChannel( - InterceptingChannelFactory factory, IOutputSessionChannel innerChannel) - : base(factory, innerChannel) - { - _innerSessionChannel = innerChannel; - } - - public IOutputSession Session - { - get - { - return _innerSessionChannel.Session; - } - } - } - - private class InterceptingRequestSessionChannel : InterceptingRequestChannel, IRequestSessionChannel - { - private IRequestSessionChannel _innerSessionChannel; - - public InterceptingRequestSessionChannel( - InterceptingChannelFactory factory, IRequestSessionChannel innerChannel) - : base(factory, innerChannel) - { - _innerSessionChannel = innerChannel; - } - - public IOutputSession Session - { - get - { - return _innerSessionChannel.Session; - } - } - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelListener.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelListener.cs deleted file mode 100644 index b95c12592fc..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingChannelListener.cs +++ /dev/null @@ -1,546 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ServiceModel; -using System.ServiceModel.Channels; - -namespace Microsoft.Samples.MessageInterceptor -{ - internal class InterceptingChannelListener - : ChannelListenerBase - where TChannel : class, IChannel - { - private ChannelMessageInterceptor _interceptor; - private IChannelListener _innerChannelListener; - - public InterceptingChannelListener(ChannelMessageInterceptor interceptor, BindingContext context) - { - _interceptor = interceptor; - _innerChannelListener = context.BuildInnerChannelListener(); - if (_innerChannelListener == null) - { - throw new InvalidOperationException( - "InterceptingChannelListener requires an inner IChannelListener."); - } - } - - public ChannelMessageInterceptor Interceptor - { - get { return _interceptor; } - } - - public override Uri Uri - { - get - { - return _innerChannelListener.Uri; - } - } - - public override T GetProperty() - { - T baseProperty = base.GetProperty(); - if (baseProperty != null) - { - return baseProperty; - } - - return _innerChannelListener.GetProperty(); - } - - protected override void OnOpen(TimeSpan timeout) - { - _innerChannelListener.Open(timeout); - } - - protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) - { - return _innerChannelListener.BeginOpen(timeout, callback, state); - } - - protected override void OnEndOpen(IAsyncResult result) - { - _innerChannelListener.EndOpen(result); - } - - protected override void OnClose(TimeSpan timeout) - { - _innerChannelListener.Close(timeout); - } - - protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) - { - return _innerChannelListener.BeginClose(timeout, callback, state); - } - - protected override void OnEndClose(IAsyncResult result) - { - _innerChannelListener.EndClose(result); - } - - protected override void OnAbort() - { - _innerChannelListener.Abort(); - } - - protected override TChannel OnAcceptChannel(TimeSpan timeout) - { - TChannel innerChannel = _innerChannelListener.AcceptChannel(timeout); - return WrapChannel(innerChannel); - } - - protected override IAsyncResult OnBeginAcceptChannel(TimeSpan timeout, AsyncCallback callback, object state) - { - return _innerChannelListener.BeginAcceptChannel(timeout, callback, state); - } - - protected override TChannel OnEndAcceptChannel(IAsyncResult result) - { - TChannel innerChannel = _innerChannelListener.EndAcceptChannel(result); - return WrapChannel(innerChannel); - } - - protected override bool OnWaitForChannel(TimeSpan timeout) - { - return _innerChannelListener.WaitForChannel(timeout); - } - - protected override IAsyncResult OnBeginWaitForChannel(TimeSpan timeout, AsyncCallback callback, object state) - { - return _innerChannelListener.BeginWaitForChannel(timeout, callback, state); - } - - protected override bool OnEndWaitForChannel(IAsyncResult result) - { - return _innerChannelListener.EndWaitForChannel(result); - } - - private TChannel WrapChannel(TChannel innerChannel) - { - if (innerChannel == null) - { - return null; - } - - if (typeof(TChannel) == typeof(IInputChannel)) - { - return (TChannel)(object)new InterceptingInputChannel(this, this.Interceptor, (IInputChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IReplyChannel)) - { - return (TChannel)(object)new InterceptingReplyChannel(this, (IReplyChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IDuplexChannel)) - { - return (TChannel)(object)new InterceptingDuplexChannel(this, Interceptor, (IDuplexChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IInputSessionChannel)) - { - return (TChannel)(object)new InterceptingInputSessionChannel(this, - (IInputSessionChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IReplySessionChannel)) - { - return (TChannel)(object)new InterceptingReplySessionChannel(this, - (IReplySessionChannel)innerChannel); - } - else if (typeof(TChannel) == typeof(IDuplexSessionChannel)) - { - return (TChannel)(object)new InterceptingDuplexSessionChannel(this, Interceptor, - (IDuplexSessionChannel)innerChannel); - } - - // Cannot wrap this channel. - return innerChannel; - } - - private class InterceptingReplyChannel : InterceptingChannelBase, IReplyChannel - { - public InterceptingReplyChannel( - InterceptingChannelListener listener, IReplyChannel innerChannel) - : base(listener, listener.Interceptor, innerChannel) - { - // empty - } - - public EndpointAddress LocalAddress - { - get - { - return this.InnerChannel.LocalAddress; - } - } - - public RequestContext ReceiveRequest() - { - return ReceiveRequest(DefaultReceiveTimeout); - } - - public RequestContext ReceiveRequest(TimeSpan timeout) - { - RequestContext requestContext; - while (true) - { - requestContext = this.InnerChannel.ReceiveRequest(timeout); - if (ProcessRequestContext(ref requestContext)) - { - break; - } - } - - return requestContext; - } - - public IAsyncResult BeginReceiveRequest(AsyncCallback callback, object state) - { - return BeginReceiveRequest(DefaultReceiveTimeout, callback, state); - } - - public IAsyncResult BeginReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state) - { - ReceiveRequestAsyncResult result = new ReceiveRequestAsyncResult(this, timeout, callback, state); - result.Begin(); - return result; - } - - public RequestContext EndReceiveRequest(IAsyncResult result) - { - return ReceiveRequestAsyncResult.End(result); - } - - public bool TryReceiveRequest(TimeSpan timeout, out RequestContext requestContext) - { - bool result; - - while (true) - { - result = this.InnerChannel.TryReceiveRequest(timeout, out requestContext); - if (!result || ProcessRequestContext(ref requestContext)) - { - break; - } - } - - return result; - } - - public IAsyncResult BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state) - { - TryReceiveRequestAsyncResult result = new TryReceiveRequestAsyncResult(this, timeout, callback, state); - result.Begin(); - return result; - } - - public bool EndTryReceiveRequest(IAsyncResult result, out RequestContext requestContext) - { - return TryReceiveRequestAsyncResult.End(result, out requestContext); - } - - public bool WaitForRequest(TimeSpan timeout) - { - return this.InnerChannel.WaitForRequest(timeout); - } - - public IAsyncResult BeginWaitForRequest(TimeSpan timeout, AsyncCallback callback, object state) - { - return this.InnerChannel.BeginWaitForRequest(timeout, callback, state); - } - - public bool EndWaitForRequest(IAsyncResult result) - { - return this.InnerChannel.EndWaitForRequest(result); - } - - private bool ProcessRequestContext(ref RequestContext requestContext) - { - if (requestContext == null) - { - return true; - } - - Message m = requestContext.RequestMessage; - Message originalMessage = m; - - this.OnReceive(ref m); - if (m != null || originalMessage == null) - { - requestContext = new InterceptingRequestContext(this, requestContext); - } - else - { - requestContext.Close(); - requestContext = null; - } - - return requestContext != null; - } - - private abstract class ReceiveRequestAsyncResultBase : AsyncResult - { - private RequestContext _requestContext; - private InterceptingReplyChannel _channel; - private AsyncCallback _onReceive; - - protected ReceiveRequestAsyncResultBase(InterceptingReplyChannel channel, - AsyncCallback callback, object state) - : base(callback, state) - { - _channel = channel; - _onReceive = new AsyncCallback(OnReceive); - } - - protected RequestContext RequestContext - { - get { return _requestContext; } - } - - public void Begin() - { - IAsyncResult result = BeginReceiveRequest(_onReceive, null); - if (result.CompletedSynchronously) - { - if (HandleReceiveComplete(result)) - { - base.Complete(true); - } - } - } - - protected abstract IAsyncResult BeginReceiveRequest(AsyncCallback callback, object state); - protected abstract RequestContext EndReceiveRequest(IAsyncResult result); - - private bool HandleReceiveComplete(IAsyncResult result) - { - while (true) - { - _requestContext = EndReceiveRequest(result); - if (_channel.ProcessRequestContext(ref _requestContext)) - { - return true; - } - - // try again - result = BeginReceiveRequest(_onReceive, null); - if (!result.CompletedSynchronously) - { - return false; - } - } - } - - private void OnReceive(IAsyncResult result) - { - if (result.CompletedSynchronously) - { - return; - } - - bool completeSelf = false; - Exception completeException = null; - try - { - completeSelf = HandleReceiveComplete(result); - } - catch (Exception e) - { - completeException = e; - completeSelf = true; - } - - if (completeSelf) - { - base.Complete(false, completeException); - } - } - } - - private class TryReceiveRequestAsyncResult : ReceiveRequestAsyncResultBase - { - private IReplyChannel _innerChannel; - private TimeSpan _timeout; - private bool _returnValue; - - public TryReceiveRequestAsyncResult(InterceptingReplyChannel channel, TimeSpan timeout, - AsyncCallback callback, object state) - : base(channel, callback, state) - { - _innerChannel = channel.InnerChannel; - _timeout = timeout; - } - - protected override IAsyncResult BeginReceiveRequest(AsyncCallback callback, object state) - { - return _innerChannel.BeginTryReceiveRequest(_timeout, callback, state); - } - - protected override RequestContext EndReceiveRequest(IAsyncResult result) - { - RequestContext requestContext; - _returnValue = _innerChannel.EndTryReceiveRequest(result, out requestContext); - return requestContext; - } - - public static bool End(IAsyncResult result, out RequestContext requestContext) - { - TryReceiveRequestAsyncResult thisPtr = AsyncResult.End(result); - requestContext = thisPtr.RequestContext; - return thisPtr._returnValue; - } - } - - private class ReceiveRequestAsyncResult : ReceiveRequestAsyncResultBase - { - private IReplyChannel _innerChannel; - private TimeSpan _timeout; - - public ReceiveRequestAsyncResult(InterceptingReplyChannel channel, TimeSpan timeout, AsyncCallback callback, object state) - : base(channel, callback, state) - { - _innerChannel = channel.InnerChannel; - _timeout = timeout; - } - - protected override IAsyncResult BeginReceiveRequest(AsyncCallback callback, object state) - { - return _innerChannel.BeginReceiveRequest(_timeout, callback, state); - } - - protected override RequestContext EndReceiveRequest(IAsyncResult result) - { - return _innerChannel.EndReceiveRequest(result); - } - - public static RequestContext End(IAsyncResult result) - { - ReceiveRequestAsyncResult thisPtr = AsyncResult.End(result); - return thisPtr.RequestContext; - } - } - - - private class InterceptingRequestContext : RequestContext - { - private InterceptingReplyChannel _channel; - private RequestContext _innerContext; - - public InterceptingRequestContext(InterceptingReplyChannel channel, RequestContext innerContext) - { - _channel = channel; - _innerContext = innerContext; - } - - public override Message RequestMessage - { - get - { - return _innerContext.RequestMessage; - } - } - - public override void Abort() - { - _innerContext.Abort(); - } - - public override IAsyncResult BeginReply(Message message, AsyncCallback callback, object state) - { - return BeginReply(message, _channel.DefaultSendTimeout, callback, state); - } - - public override IAsyncResult BeginReply(Message message, TimeSpan timeout, AsyncCallback callback, object state) - { - Message m = message; - this.OnSend(ref m); - return _innerContext.BeginReply(m, timeout, callback, state); - } - - public override void Close() - { - _innerContext.Close(); - } - - public override void Close(TimeSpan timeout) - { - _innerContext.Close(timeout); - } - - protected override void Dispose(bool disposing) - { - try - { - if (disposing) - ((IDisposable)_innerContext).Dispose(); - } - finally - { - base.Dispose(disposing); - } - } - - public override void EndReply(IAsyncResult result) - { - _innerContext.EndReply(result); - } - - private void OnSend(ref Message message) - { - _channel.OnSend(ref message); - } - - public override void Reply(Message message) - { - Reply(message, _channel.DefaultSendTimeout); - } - - public override void Reply(Message message, TimeSpan timeout) - { - Message m = message; - this.OnSend(ref m); - _innerContext.Reply(m, timeout); - } - } - } - - private class InterceptingInputSessionChannel : InterceptingInputChannel, IInputSessionChannel - { - private IInputSessionChannel _innerSessionChannel; - - public InterceptingInputSessionChannel( - InterceptingChannelListener listener, IInputSessionChannel innerChannel) - : base(listener, listener.Interceptor, innerChannel) - { - _innerSessionChannel = innerChannel; - } - - public IInputSession Session - { - get - { - return _innerSessionChannel.Session; - } - } - } - - private class InterceptingReplySessionChannel : InterceptingReplyChannel, IReplySessionChannel - { - private IReplySessionChannel _innerSessionChannel; - - public InterceptingReplySessionChannel( - InterceptingChannelListener listener, IReplySessionChannel innerChannel) - : base(listener, innerChannel) - { - _innerSessionChannel = innerChannel; - } - - public IInputSession Session - { - get - { - return _innerSessionChannel.Session; - } - } - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingDuplexChannel.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingDuplexChannel.cs deleted file mode 100644 index 946f2a82585..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/InterceptingDuplexChannel.cs +++ /dev/null @@ -1,337 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ServiceModel; -using System.ServiceModel.Channels; - -namespace Microsoft.Samples.MessageInterceptor -{ - internal class InterceptingInputChannel - : InterceptingChannelBase, IInputChannel - where TChannel : class, IInputChannel - { - public InterceptingInputChannel( - ChannelManagerBase manager, ChannelMessageInterceptor interceptor, TChannel innerChannel) - : base(manager, interceptor, innerChannel) - { - // empty - } - - public EndpointAddress LocalAddress - { - get - { - return this.InnerChannel.LocalAddress; - } - } - - private bool ProcessReceivedMessage(ref Message message) - { - Message originalMessage = message; - this.OnReceive(ref message); - return (message != null || originalMessage == null); - } - - public Message Receive() - { - return Receive(DefaultReceiveTimeout); - } - - public Message Receive(TimeSpan timeout) - { - Message message; - while (true) - { - message = this.InnerChannel.Receive(timeout); - if (ProcessReceivedMessage(ref message)) - { - break; - } - } - - return message; - } - - public IAsyncResult BeginReceive(AsyncCallback callback, object state) - { - return BeginReceive(DefaultReceiveTimeout, callback, state); - } - - public IAsyncResult BeginReceive(TimeSpan timeout, AsyncCallback callback, object state) - { - ReceiveAsyncResult result = new ReceiveAsyncResult(this, timeout, callback, state); - result.Begin(); - return result; - } - - public Message EndReceive(IAsyncResult result) - { - return ReceiveAsyncResult.End(result); - } - - public bool TryReceive(TimeSpan timeout, out Message message) - { - bool result; - while (true) - { - result = this.InnerChannel.TryReceive(timeout, out message); - if (ProcessReceivedMessage(ref message)) - { - break; - } - } - - return result; - } - - public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state) - { - TryReceiveAsyncResult result = new TryReceiveAsyncResult(this, timeout, callback, state); - result.Begin(); - return result; - } - - public bool EndTryReceive(IAsyncResult result, out Message message) - { - return TryReceiveAsyncResult.End(result, out message); - } - - public bool WaitForMessage(TimeSpan timeout) - { - return this.InnerChannel.WaitForMessage(timeout); - } - - public IAsyncResult BeginWaitForMessage(TimeSpan timeout, AsyncCallback callback, object state) - { - return this.InnerChannel.BeginWaitForMessage(timeout, callback, state); - } - - public bool EndWaitForMessage(IAsyncResult result) - { - return this.InnerChannel.EndWaitForMessage(result); - } - - private abstract class ReceiveAsyncResultBase : AsyncResult - where TInputChannel : class, IInputChannel - { - private Message _message; - private InterceptingInputChannel _channel; - private AsyncCallback _onReceive; - - protected ReceiveAsyncResultBase(InterceptingInputChannel channel, - AsyncCallback callback, object state) - : base(callback, state) - { - _channel = channel; - _onReceive = new AsyncCallback(OnReceive); - } - - protected Message Message - { - get { return _message; } - } - - public void Begin() - { - IAsyncResult result = BeginReceive(_onReceive, null); - if (result.CompletedSynchronously) - { - if (HandleReceiveComplete(result)) - { - base.Complete(true); - } - } - } - - protected abstract IAsyncResult BeginReceive(AsyncCallback callback, object state); - protected abstract Message EndReceive(IAsyncResult result); - - private bool HandleReceiveComplete(IAsyncResult result) - { - while (true) - { - _message = EndReceive(result); - if (_channel.ProcessReceivedMessage(ref _message)) - { - return true; - } - - // try again - result = BeginReceive(_onReceive, null); - if (!result.CompletedSynchronously) - { - return false; - } - } - } - - private void OnReceive(IAsyncResult result) - { - if (result.CompletedSynchronously) - { - return; - } - - bool completeSelf = false; - Exception completeException = null; - try - { - completeSelf = HandleReceiveComplete(result); - } - catch (Exception e) - { - completeException = e; - completeSelf = true; - } - - if (completeSelf) - { - base.Complete(false, completeException); - } - } - } - - private class TryReceiveAsyncResult : ReceiveAsyncResultBase - where TInputChannel : class, IInputChannel - { - private TInputChannel _innerChannel; - private TimeSpan _timeout; - private bool _returnValue; - - public TryReceiveAsyncResult(InterceptingInputChannel channel, TimeSpan timeout, - AsyncCallback callback, object state) - : base(channel, callback, state) - { - _innerChannel = channel.InnerChannel; - _timeout = timeout; - } - - protected override IAsyncResult BeginReceive(AsyncCallback callback, object state) - { - return _innerChannel.BeginTryReceive(_timeout, callback, state); - } - - protected override Message EndReceive(IAsyncResult result) - { - Message message; - _returnValue = _innerChannel.EndTryReceive(result, out message); - return message; - } - - public static bool End(IAsyncResult result, out Message message) - { - TryReceiveAsyncResult thisPtr = AsyncResult.End>(result); - message = thisPtr.Message; - return thisPtr._returnValue; - } - } - - private class ReceiveAsyncResult : ReceiveAsyncResultBase - where TInputChannel : class, IInputChannel - { - private TInputChannel _innerChannel; - private TimeSpan _timeout; - - public ReceiveAsyncResult(InterceptingInputChannel channel, TimeSpan timeout, - AsyncCallback callback, object state) - : base(channel, callback, state) - { - _innerChannel = channel.InnerChannel; - _timeout = timeout; - } - - protected override IAsyncResult BeginReceive(AsyncCallback callback, object state) - { - return _innerChannel.BeginReceive(_timeout, callback, state); - } - - protected override Message EndReceive(IAsyncResult result) - { - return _innerChannel.EndReceive(result); - } - - public static Message End(IAsyncResult result) - { - ReceiveAsyncResult thisPtr = AsyncResult.End>(result); - return thisPtr.Message; - } - } - } - - internal class InterceptingDuplexChannel - : InterceptingInputChannel, IDuplexChannel - { - public InterceptingDuplexChannel( - ChannelManagerBase manager, ChannelMessageInterceptor interceptor, IDuplexChannel innerChannel) - : base(manager, interceptor, innerChannel) - { - // empty - } - - public EndpointAddress RemoteAddress - { - get - { - return this.InnerChannel.RemoteAddress; - } - } - - public Uri Via - { - get - { - return this.InnerChannel.Via; - } - } - - public void Send(Message message) - { - Send(message, DefaultSendTimeout); - } - - public void Send(Message message, TimeSpan timeout) - { - this.OnSend(ref message); - this.InnerChannel.Send(message, timeout); - } - - public IAsyncResult BeginSend(Message message, AsyncCallback callback, object state) - { - return BeginSend(message, DefaultSendTimeout, callback, state); - } - - public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state) - { - this.OnSend(ref message); - return this.InnerChannel.BeginSend(message, timeout, callback, state); - } - - public void EndSend(IAsyncResult result) - { - this.InnerChannel.EndSend(result); - } - } - - - internal class InterceptingDuplexSessionChannel : InterceptingDuplexChannel, IDuplexSessionChannel - { - private IDuplexSessionChannel _innerSessionChannel; - - public InterceptingDuplexSessionChannel( - ChannelManagerBase manager, ChannelMessageInterceptor interceptor, IDuplexSessionChannel innerChannel) - : base(manager, interceptor, innerChannel) - { - _innerSessionChannel = innerChannel; - } - - public IDuplexSession Session - { - get - { - return _innerSessionChannel.Session; - } - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/Interceptingelement.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/Interceptingelement.cs deleted file mode 100644 index efe88263a31..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/Interceptingelement.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ServiceModel.Channels; -using System.ServiceModel.Configuration; - -namespace Microsoft.Samples.MessageInterceptor -{ - /// - /// Configuration class for InterceptingBindingElement. To make your InterceptingBindingElement - /// configurable, derive from InterceptingElementInterceptingElement and override CreateMessageInterceptor() - /// - public abstract class InterceptingElement : BindingElementExtensionElement - { - protected InterceptingElement() - : base() - { - } - - public override Type BindingElementType - { - get - { - return typeof(InterceptingBindingElement); - } - } - - protected abstract ChannelMessageInterceptor CreateMessageInterceptor(); - - protected override BindingElement CreateBindingElement() - { - return new InterceptingBindingElement(CreateMessageInterceptor()); - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/KnownTypeA.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/KnownTypeA.cs index b71eb76a1cb..8a36a43b3d8 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/KnownTypeA.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/KnownTypeA.cs @@ -1,7 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if !NET using System.Runtime.Serialization; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/MyX509CertificateValidator.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/MyX509CertificateValidator.cs index a8dc0537d94..aafb5020d8c 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/MyX509CertificateValidator.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/MyX509CertificateValidator.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.IdentityModel.Selectors; +using CoreWCF.IdentityModel.Tokens; +#else using System; using System.IdentityModel.Selectors; using System.IdentityModel.Tokens; +#endif using System.Security.Cryptography.X509Certificates; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.4.4.0.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.4.4.0.cs index 55584e436db..09ed48b8188 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.4.4.0.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.4.4.0.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.cs index 5feaf87ce03..35ece5b9af3 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingDataNotWrapped.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingDataNotWrapped.cs index 1145dd95dcf..05fcfdf7b58 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingDataNotWrapped.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingDataNotWrapped.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.4.4.0.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.4.4.0.cs index 464502bc760..91e06161d6a 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.4.4.0.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.4.4.0.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.cs index 39988112052..cc4de9f6f0c 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/Service1.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/Service1.cs index 7608f8ae933..7044c744dbc 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/Service1.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/Service1.cs @@ -2,7 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceActivationsBuilder.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceActivationsBuilder.cs index 50cffd1aa85..30296d09f70 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceActivationsBuilder.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceActivationsBuilder.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System.Configuration; using System.ServiceModel.Configuration; @@ -34,3 +35,4 @@ private void UpdateServiceActivations(ServiceHostingEnvironmentSection serviceHo } } +#endif diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceContractAsyncInterfaces.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceContractAsyncInterfaces.cs index 8f52beae18b..e8efca608bc 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceContractAsyncInterfaces.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceContractAsyncInterfaces.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceContractAsyncServices.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceContractAsyncServices.cs index 625e10a0ac4..139491ccd2e 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceContractAsyncServices.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ServiceContractAsyncServices.cs @@ -2,7 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System.Linq; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/SessionTestsService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/SessionTestsService.cs index e5c2bc29f52..73758c0f76f 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/SessionTestsService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/SessionTestsService.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; using System.Threading; +#endif namespace WcfService { 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 a3156afbcd9..e946eddeabb 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestDefinitionHelper.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestDefinitionHelper.cs @@ -2,10 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // 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; +#else using System; using System.Collections.Generic; using System.Linq; using System.ServiceModel; +#endif namespace WcfService { @@ -14,11 +24,11 @@ internal class TestDefinitionHelper private static IDictionary s_baseAddresses = null; private const int DefaultHttpPort = 8081; private const int DefaultHttpsPort = 44285; - private const int DefaultTcpPort = 809; + private const int DefaultTcpPort = 8808; private const int DefaultWebSocketPort = 8083; private const int DefaultWebSocketSPort = 8084; - private static IDictionary BaseAddresses + internal static IDictionary BaseAddresses { get { @@ -28,17 +38,24 @@ private static IDictionary BaseAddresses var httpPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("httpPort")) ? DefaultHttpPort : int.Parse(Environment.GetEnvironmentVariable("httpPort")); dict[ServiceSchema.HTTP] = string.Format(@"http://localhost:{0}", httpPort); var httpsPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("httpsPort")) ? DefaultHttpsPort : int.Parse(Environment.GetEnvironmentVariable("httpsPort")); - dict[ServiceSchema.HTTPS]= string.Format(@"https://localhost:{0}", httpsPort); + dict[ServiceSchema.HTTPS] = string.Format(@"https://localhost:{0}", httpsPort); var tcpPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("tcpPort")) ? DefaultTcpPort : int.Parse(Environment.GetEnvironmentVariable("tcpPort")); dict[ServiceSchema.NETTCP] = string.Format(@"net.tcp://localhost:{0}", tcpPort); +#if NET + var websocketPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketPort")) ? DefaultWebSocketPort : int.Parse(Environment.GetEnvironmentVariable("websocketPort")); + dict[ServiceSchema.WS] = string.Format(@"ws://localhost:{0}", websocketPort); + var websocketsPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketsPort")) ? DefaultWebSocketSPort : int.Parse(Environment.GetEnvironmentVariable("websocketsPort")); + dict[ServiceSchema.WSS] = string.Format(@"wss://localhost:{0}", websocketsPort); +#else var websocketPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketPort")) ? DefaultWebSocketPort : int.Parse(Environment.GetEnvironmentVariable("websocketPort")); dict[ServiceSchema.WS] = string.Format(@"http://localhost:{0}", websocketPort); var websocketsPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketsPort")) ? DefaultWebSocketSPort : int.Parse(Environment.GetEnvironmentVariable("websocketsPort")); dict[ServiceSchema.WSS] = string.Format(@"https://localhost:{0}", websocketsPort); +#endif s_baseAddresses = dict; dict[ServiceSchema.NETPIPE] = @"net.pipe://localhost"; Console.WriteLine("Using base addresses:"); - foreach(var ba in dict.Values) + foreach (var ba in dict.Values) { Console.WriteLine("\t" + ba); } @@ -48,7 +65,193 @@ private static IDictionary BaseAddresses } } - internal static void StartHosts() +#if NET + internal class ServiceTestHostOptions + { + public List serviceBaseAddresses = new List(); + public Dictionary endpointBasePath = new Dictionary(); + } + + internal static async Task StartHosts() + { + bool success = true; + var serviceTestHostOptionsDict = new Dictionary(); + + var webHost = new WebHostBuilder() + .ConfigureLogging((ILoggingBuilder logging) => + { + logging.ClearProviders(); + logging.AddConsole(); + logging.AddFilter("Default", LogLevel.Debug); + logging.AddFilter("Microsoft", LogLevel.Debug); + logging.SetMinimumLevel(LogLevel.Debug); + }) + .UseKestrel(options => + { + options.Listen(IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.HTTP]).Port); + options.Listen(IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.HTTPS]).Port, listenOptions => + { + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + Debug.Assert(cert != null, "couldn't find the server certificate"); + + listenOptions.UseHttps(cert); + + if (Debugger.IsAttached) + { + listenOptions.UseConnectionLogging(); + } + }); + options.Listen(IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.WS]).Port); + options.Listen(IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.WSS]).Port, listenOptions => + { + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + listenOptions.UseHttps(cert); + + if (Debugger.IsAttached) + { + listenOptions.UseConnectionLogging(); + } + }); + }) + .UseNetTcp(IPAddress.IPv6Any, new Uri(BaseAddresses[ServiceSchema.NETTCP]).Port) + .ConfigureServices(services => + { + services.AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme) + .AddBasic(options => + { + options.Realm = "Basic Authentication"; + options.Events = new BasicAuthenticationEvents + { + OnValidateCredentials = context => + { + if (context.Username == context.Password) + { + var claims = new[] + { + new Claim(ClaimTypes.NameIdentifier, context.Username, ClaimValueTypes.String, context.Options.ClaimsIssuer), + new Claim(ClaimTypes.Name, context.Username, ClaimValueTypes.String, context.Options.ClaimsIssuer) + }; + + context.Principal = new ClaimsPrincipal(new ClaimsIdentity(claims, context.Scheme.Name)); + context.Success(); + } + + return Task.CompletedTask; + } + }; + }); + services.AddServiceModelServices() + .AddServiceModelMetadata() + .AddServiceModelWebServices() + .AddRouting() + .AddAuthorization(); + }) + .Configure(app => + { + app.UseAuthentication(); + app.UseAuthorization(); + app.UseServiceModel(serviceBuilder => + { + foreach (var serviceTestHost in GetAttributedServiceHostTypes()) + { + var serviceTestHostOptions = new ServiceTestHostOptions(); + foreach (TestServiceDefinitionAttribute attr in serviceTestHost.GetCustomAttributes(typeof(TestServiceDefinitionAttribute), false)) + { + Uri serviceBaseAddress = null; + try + { + foreach (Enum schema in Enum.GetValues(typeof(ServiceSchema))) + { + if (attr.Schema.HasFlag(schema)) + { + serviceTestHostOptions.endpointBasePath.Add(schema, attr.BasePath); + serviceBaseAddress = new Uri(BaseAddresses[(ServiceSchema)schema]); + serviceTestHostOptions.serviceBaseAddresses.Add(serviceBaseAddress); + } + } + } + catch (Exception e) + { + ConsoleColor bg = Console.BackgroundColor; + ConsoleColor fg = Console.ForegroundColor; + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Problem creating base address for servicehost type " + serviceTestHost.Name + " with schema " + attr.Schema + " and address " + serviceBaseAddress == null ? string.Empty : serviceBaseAddress.ToString()); + Console.WriteLine(e); + Console.BackgroundColor = bg; + Console.ForegroundColor = fg; + success = false; + break; + } + } + + serviceTestHostOptionsDict.Add(serviceTestHost.Name, serviceTestHostOptions); + try + { + if (success) + { + string serviceHostTypeName = serviceTestHost.Name; + var serviceHost = (ServiceHost)Activator.CreateInstance(serviceTestHost, serviceTestHostOptionsDict[serviceHostTypeName].serviceBaseAddresses.ToArray()); + serviceBuilder.AddService(serviceHost.ServiceType, options => + { + var localHostTypeName = serviceHostTypeName; + options.BaseAddresses.Clear(); + foreach (var baseAddress in BaseAddresses.Values) + { + //if (!options.BaseAddresses.Contains(baseAddress)) + options.BaseAddresses.Add(new Uri(baseAddress)); + } + }); + + foreach (var endpoint in serviceHost.Endpoints) + { + Enum schema = ServiceHostHelper.ToServiceSchema(endpoint.Binding.Scheme); + string basePath = serviceTestHostOptionsDict[serviceHostTypeName].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 (serviceTestHostOptionsDict[localHostTypeName].serviceBaseAddresses.Where(uri => uri.Scheme == Uri.UriSchemeHttps).Any()) + { + smb.HttpsGetEnabled = true; + } + + smb.HttpGetEnabled = true; + serviceHost.ApplyConfig(serviceHostBase); + }); + } + } + catch (Exception e) + { + ConsoleColor bg = Console.BackgroundColor; + ConsoleColor fg = Console.ForegroundColor; + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Problem starting servicehost type " + serviceTestHost.Name); + Console.WriteLine(e); + Console.BackgroundColor = bg; + Console.ForegroundColor = fg; + } + } + + }); + }).Build(); + + await webHost.StartAsync(); + } + + internal static IEnumerable GetAttributedServiceHostTypes() + { + var allTypes = typeof(TestDefinitionHelper).Assembly.GetTypes(); + var serviceHostTypes = from t in allTypes where (typeof(ServiceHost).IsAssignableFrom(t)) select t; + return from sht in serviceHostTypes where (sht.GetCustomAttributes(typeof(TestServiceDefinitionAttribute), false).Length > 0) select sht; + } +#else +internal static void StartHosts() { foreach (var sht in GetAttributedServiceHostTypes()) { @@ -125,5 +328,7 @@ internal static IEnumerable GetAttributedServiceHostTypes() var serviceHostTypes = from t in allTypes where (typeof(ServiceHostBase).IsAssignableFrom(t)) select t; return from sht in serviceHostTypes where (sht.GetCustomAttributes(typeof(TestServiceDefinitionAttribute), false).Length > 0) select sht; } +#endif + } } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs index cc592f44cb7..d3a8b2e92fe 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs @@ -2,16 +2,21 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Web; +#else using System; using System.IO; -using System.Net; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Web; +#endif +using System.Net; +using System.Security.Cryptography.X509Certificates; using System.Text; +using WcfTestCommon; using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2; - namespace WcfService { [ServiceContract] @@ -48,6 +53,12 @@ public interface ITestHost [OperationContract] [WebGet(UriTemplate = "State", BodyStyle = WebMessageBodyStyle.Bare)] Stream State(); + +#if NET + [OperationContract] + [WebGet(UriTemplate = "Shutdown", BodyStyle = WebMessageBodyStyle.Bare)] + void Shutdown(); +#endif } public class TestHost : ITestHost @@ -55,14 +66,14 @@ public class TestHost : ITestHost public Stream ClientCert(bool asPem) { X509Certificate2 clientCert = CertificateFromSubject(StoreName.My, StoreLocation.LocalMachine, "WCF Client Certificate"); - byte[] response; + byte[] response; if (clientCert == null) { WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError; response = Encoding.UTF8.GetBytes("Client certificate not found on system"); } - else + else { if (asPem) { @@ -95,7 +106,7 @@ public Stream Crl() public Stream RootCert(bool asPem) { X509Certificate2 rootCert = CertificateFromSubject(StoreName.Root, StoreLocation.LocalMachine, "DO_NOT_TRUST_WcfBridgeRootCA"); - byte[] response; + byte[] response; if (rootCert == null) { @@ -202,7 +213,7 @@ public static X509Certificate2 CertificateFromSubject(StoreName name, StoreLocat try { - store = new X509Store(name, location); + store = CertificateHelper.GetX509Store(name, location); store.Open(OpenFlags.ReadOnly); X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindBySubjectName, subjectName, validOnly: true); return foundCertificates.Count == 0 ? null : foundCertificates[0]; @@ -222,13 +233,15 @@ public static X509Certificate2 CertificateFromFriendlyName(StoreName name, Store try { - store = new X509Store(name, location); + store = CertificateHelper.GetX509Store(name, location); store.Open(OpenFlags.ReadOnly); X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindByIssuerName, "DO_NOT_TRUST_WcfBridgeRootCA", false); + string friendlyNameHash = CertificateGenerator.HashFriendlyNameToString(friendlyName); foreach (X509Certificate2 cert in foundCertificates) { - if (cert.FriendlyName == friendlyName) + // Search by serial number in Linux/MacOS + if (cert.FriendlyName == friendlyName || cert.SerialNumber == friendlyNameHash) { return cert; } @@ -271,5 +284,10 @@ public static string GetCertificateAsPem(X509Certificate2 certificate) return builder.ToString(); } + + public void Shutdown() + { + Environment.Exit(0); + } } } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHttpRequestMessageProperty.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHttpRequestMessageProperty.cs index e8aa0331549..a8dd15384a3 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHttpRequestMessageProperty.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHttpRequestMessageProperty.cs @@ -2,8 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System.Collections.Generic; using System.Runtime.Serialization; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestServiceDefinitionAttribute.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestServiceDefinitionAttribute.cs index 79c1d4b9749..ae22093981a 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestServiceDefinitionAttribute.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestServiceDefinitionAttribute.cs @@ -2,7 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TimeoutHelper.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TimeoutHelper.cs deleted file mode 100644 index 4b11d8fa0a9..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TimeoutHelper.cs +++ /dev/null @@ -1,198 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Threading; - -namespace Microsoft.Samples.MessageInterceptor -{ - public struct TimeoutHelper - { - public static TimeSpan DefaultTimeout { get { return TimeSpan.FromMinutes(2); } } - public static TimeSpan DefaultShortTimeout { get { return TimeSpan.FromSeconds(4); } } - public static TimeSpan Infinite { get { return TimeSpan.MaxValue; } } - private DateTime _deadline; - private TimeSpan _originalTimeout; - - public TimeoutHelper(TimeSpan timeout) - { - if (timeout < TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException("timeout"); - } - - _originalTimeout = timeout; - if (timeout == TimeSpan.MaxValue) - { - _deadline = DateTime.MaxValue; - } - else - { - _deadline = DateTime.UtcNow + timeout; - } - } - - public TimeSpan OriginalTimeout - { - get { return _originalTimeout; } - } - - public TimeSpan RemainingTime() - { - if (_deadline == DateTime.MaxValue) - { - return TimeSpan.MaxValue; - } - else - { - TimeSpan remaining = _deadline - DateTime.UtcNow; - if (remaining <= TimeSpan.Zero) - { - return TimeSpan.Zero; - } - else - { - return remaining; - } - } - } - public void SetTimer(TimerCallback callback, Object state) - { - Timer timer = new Timer(callback, state, TimeoutHelper.ToMilliseconds(this.RemainingTime()), Timeout.Infinite); - } - - public static TimeSpan FromMilliseconds(int milliseconds) - { - if (milliseconds == Timeout.Infinite) - { - return TimeSpan.MaxValue; - } - else - { - return TimeSpan.FromMilliseconds(milliseconds); - } - } - - public static int ToMilliseconds(TimeSpan timeout) - { - if (timeout == TimeSpan.MaxValue) - { - return Timeout.Infinite; - } - else - { - long ticks = Ticks.FromTimeSpan(timeout); - if (ticks / TimeSpan.TicksPerMillisecond > int.MaxValue) - { - return int.MaxValue; - } - return Ticks.ToMilliseconds(ticks); - } - } - - public static TimeSpan Add(TimeSpan timeout1, TimeSpan timeout2) - { - return Ticks.ToTimeSpan(Ticks.Add(Ticks.FromTimeSpan(timeout1), Ticks.FromTimeSpan(timeout2))); - } - - public static DateTime Add(DateTime time, TimeSpan timeout) - { - if (timeout >= TimeSpan.Zero && DateTime.MaxValue - time <= timeout) - { - return DateTime.MaxValue; - } - if (timeout <= TimeSpan.Zero && DateTime.MinValue - time >= timeout) - { - return DateTime.MinValue; - } - return time + timeout; - } - - public static DateTime Subtract(DateTime time, TimeSpan timeout) - { - return Add(time, TimeSpan.Zero - timeout); - } - - public static TimeSpan Divide(TimeSpan timeout, int factor) - { - if (timeout == TimeSpan.MaxValue) - { - return TimeSpan.MaxValue; - } - - return Ticks.ToTimeSpan((Ticks.FromTimeSpan(timeout) / factor) + 1); - } - - public static bool WaitOne(WaitHandle waitHandle, TimeSpan timeout, bool exitSync) - { - if (timeout == TimeSpan.MaxValue) - { - waitHandle.WaitOne(); - return true; - } - else - { - TimeSpan maxWait = TimeSpan.FromMilliseconds(Int32.MaxValue); - - while (timeout > maxWait) - { - bool signaled = waitHandle.WaitOne(maxWait, exitSync); - - if (signaled) - { - return true; - } - - timeout -= maxWait; - } - - return waitHandle.WaitOne(timeout, exitSync); - } - } - - private static class Ticks - { - public static long FromMilliseconds(int milliseconds) - { - return (long)milliseconds * TimeSpan.TicksPerMillisecond; - } - - public static int ToMilliseconds(long ticks) - { - return checked((int)(ticks / TimeSpan.TicksPerMillisecond)); - } - - public static long FromTimeSpan(TimeSpan duration) - { - return duration.Ticks; - } - - public static TimeSpan ToTimeSpan(long ticks) - { - return new TimeSpan(ticks); - } - - public static long Add(long firstTicks, long secondTicks) - { - if (firstTicks == long.MaxValue || firstTicks == long.MinValue) - { - return firstTicks; - } - if (secondTicks == long.MaxValue || secondTicks == long.MinValue) - { - return secondTicks; - } - if (firstTicks >= 0 && long.MaxValue - firstTicks <= secondTicks) - { - return long.MaxValue - 1; - } - if (firstTicks <= 0 && long.MinValue - firstTicks >= secondTicks) - { - return long.MinValue + 1; - } - return checked(firstTicks + secondTicks); - } - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/UnderstoodHeaders.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/UnderstoodHeaders.cs index 33fc245d89b..7b0fa6a0c4d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/UnderstoodHeaders.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/UnderstoodHeaders.cs @@ -2,8 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/UniqueType.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/UniqueType.cs index 78a6777b69b..e7d98b0965b 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/UniqueType.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/UniqueType.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. - - public class UniqueType { public string stringValue; diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/VerifyWebSockets.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/VerifyWebSockets.cs index 77a4c525770..5129509b6f1 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/VerifyWebSockets.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/VerifyWebSockets.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WSDuplexService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WSDuplexService.cs index 52a4ad97b40..1128a3b463e 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WSDuplexService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WSDuplexService.cs @@ -2,12 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.Collections.Generic; using System.IO; using System.ServiceModel; using System.Threading; using System.Threading.Tasks; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WSRequestReplyService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WSRequestReplyService.cs index 0b233eb94a2..066d83ce069 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WSRequestReplyService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WSRequestReplyService.cs @@ -2,13 +2,18 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.IO; -using System.Net.NetworkInformation; using System.ServiceModel; using System.ServiceModel.Channels; using System.Threading; +#endif +using System.Net.NetworkInformation; namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfChannelExtensibilityService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfChannelExtensibilityService.cs deleted file mode 100644 index 3d74a9b9eab..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfChannelExtensibilityService.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.Samples.MessageInterceptor; -using System.ServiceModel; -using System.ServiceModel.Channels; - -namespace WcfService -{ - [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] - public class WcfChannelExtensiblityService : IWcfChannelExtensibilityContract - { - public void ReportWindSpeed(int speed) - { - // All the real work for this test is done in DroppingServerInterceptor.OnReceive - } - } - - internal class DroppingServerElement : InterceptingElement - { - protected override ChannelMessageInterceptor CreateMessageInterceptor() - { - return new DroppingServerInterceptor(); - } - } - - public class DroppingServerInterceptor : ChannelMessageInterceptor - { - public DroppingServerInterceptor() { } - - public override void OnReceive(ref Message msg) - { - // Verify the additional Header inserted by the ChannelMessageInterceptor exists - if (msg.Headers.FindHeader("ByPass", "urn:InterceptorNamespace") > 0) - { - return; - } - // Drop incoming Message if the Message does not have the special header - msg = null; - } - - public override ChannelMessageInterceptor Clone() - { - return new DroppingServerInterceptor(); - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfDecompService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfDecompService.cs index 3e0963f74e5..cef3f1966bf 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfDecompService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfDecompService.cs @@ -2,14 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.IO; -using System.Net; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Web; using System.Text; +#endif +using System.Net; namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfDuplexService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfDuplexService.cs index 2a902f5678b..8e1e82989a5 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfDuplexService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfDuplexService.cs @@ -2,10 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.IO; using System.ServiceModel; using System.Threading.Tasks; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfReliableService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfReliableService.cs index 8dff3d234eb..ea8a7f274d6 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfReliableService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfReliableService.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; using System.Threading; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfRestartService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfRestartService.cs index 586c7bf8cb2..0bf99d5f3ad 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfRestartService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfRestartService.cs @@ -2,14 +2,47 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.Collections.Generic; using System.ServiceModel; +#endif namespace WcfService { public class WcfRestartService : IWcfRestartService { +#if NET + public static Dictionary webHostDictionary = new Dictionary(); + + public string RestartService(Guid uniqueIdentifier) + { + IWebHost host; + + if (!webHostDictionary.TryGetValue(uniqueIdentifier, out host)) + { + throw new FaultException(String.Format("Failed to get the ServiceHost from the Dictionary.\nThe provided Guid did not match any key in the Dictionary.\nThe provided Guid was: {0}", uniqueIdentifier.ToString())); + } + + host.StopAsync().Wait(); + // cleanup dictionary + webHostDictionary.Remove(uniqueIdentifier); + return "This should never get back to the client."; + } + + public string NonRestartService(Guid uniqueIdentifier) + { + IWebHost host; + + if (!webHostDictionary.TryGetValue(uniqueIdentifier, out host)) + { + throw new FaultException(String.Format("Failed to get the ServiceHost from the Dictionary.\nThe provided Guid did not match any key in the Dictionary.\nThe provided Guid was: {0}", uniqueIdentifier.ToString())); + } + return "Success!"; + } +#else public static Dictionary serviceHostDictionary = new Dictionary(); public string RestartService(Guid uniqueIdentifier) @@ -36,5 +69,6 @@ public string NonRestartService(Guid uniqueIdentifier) } return "Success!"; } +#endif } } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfService.4.4.0.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfService.4.4.0.cs index 5ae0e7ba680..dbfd23b4abb 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfService.4.4.0.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfService.4.4.0.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfService.cs index 1cd313715bf..b1f8af70265 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfService.cs @@ -2,15 +2,23 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Configuration; +using CoreWCF.Web; +using Microsoft.AspNetCore; +#else using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; -using System.Security.Principal; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Web; +#endif +using System.Net; +using System.Security.Principal; using System.Text; namespace WcfService @@ -238,6 +246,52 @@ public TestHttpRequestMessageProperty EchoHttpRequestMessageProperty() return null; } +#if NET + public string GetRestartServiceEndpoint() + { + IWebHost host = WebHost.CreateDefaultBuilder().UseKestrel(options => + { + options.Listen(IPAddress.Loopback, 0); + }).UseStartup().Build(); + + host.Run(); + + BasicHttpBindingStartup startupService = new BasicHttpBindingStartup(); + string endpointAddress = startupService.GetEndpointAddress(); + Guid guid = startupService.GetServiceGuid(); + + // Add the WebHost instance to a static dictionary so that it can be used by restart service operation to close the WebHost + WcfRestartService.webHostDictionary.Add(guid, host); + + // Return the unique endpoint for this WebHost instance of the WcfRestartService + return "http://[HOST]" + endpointAddress; + } + + public class BasicHttpBindingStartup + { + private readonly Guid _guid = Guid.NewGuid(); + private readonly string _localHost = "http://localhost:0"; + private readonly string _path = "WindowsCommunicationFoundationTest"; + + public void ConfigureServices(IServiceCollection services) + { + services.AddServiceModelServices(); + } + + public void Configure(IApplicationBuilder app) + { + string endpointAddress = $"{_localHost}/{_path}/{_guid}"; + app.UseServiceModel(builder => + { + builder.AddService() + .AddServiceEndpoint(new BasicHttpBinding(BasicHttpSecurityMode.None), endpointAddress); + }); + } + + public string GetEndpointAddress() => $"/{_path}/{_guid}"; + public Guid GetServiceGuid() => _guid; + } +#else public string GetRestartServiceEndpoint() { BasicHttpBinding binding = new BasicHttpBinding(); @@ -256,6 +310,7 @@ public string GetRestartServiceEndpoint() // Return the unique endpoint for this ServiceHost instance of the WcfRestartService return "http://[HOST]" + path; } +#endif public string GetRequestCustomHeader(string customHeaderName, string customHeaderNamespace) { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfSoapService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfSoapService.cs index e560d247647..a86d8133a6a 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfSoapService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfSoapService.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; +#endif using System.Xml.Serialization; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfWebSocketService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfWebSocketService.cs index 2f8cbcd14d7..ac49d315c65 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfWebSocketService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/WcfWebSocketService.cs @@ -2,14 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; using System.ServiceModel.Activation; using System.Threading.Tasks; +#endif namespace WcfService { +#if !NET [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] +#endif public class WcfWebSocketService : IWcfDuplexService { public static IWcfDuplexServiceCallback callback; @@ -21,7 +27,9 @@ public void Ping(Guid guid) } } +#if !NET [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] +#endif public class WcfWebSocketTransportUsageAlwaysService : IWcfDuplexService { public static IWcfDuplexServiceCallback callback; diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlElementMessageHeader.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlElementMessageHeader.cs index 4ab100d13e7..da56f44eae3 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlElementMessageHeader.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlElementMessageHeader.cs @@ -2,8 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System.ServiceModel; using System.ServiceModel.Channels; +#endif using System.Xml.Serialization; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlSerFormatAttrServices.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlSerFormatAttrServices.cs index c1b8a5c1058..c84f61ead11 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlSerFormatAttrServices.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlSerFormatAttrServices.cs @@ -2,11 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Collections.Concurrent; using System.IO; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Collections.Concurrent; using System.Xml; using System.Xml.Serialization; diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlSerializerFormatAttribute.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlSerializerFormatAttribute.cs index 1df3ae1c99a..4ee2f227080 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlSerializerFormatAttribute.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/XmlSerializerFormatAttribute.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System.ServiceModel; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/mahjong.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/mahjong.cs index b077823c6a9..906587a515a 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/mahjong.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/mahjong.cs @@ -2,7 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if !NET using System.Runtime.Serialization; +#endif namespace WcfService { @@ -80,4 +82,4 @@ public enum ErrorCode UserNotAuthenticated = 0x191 } } -} \ No newline at end of file +} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/AuthenticationResourceHelper.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/AuthenticationResourceHelper.cs index 8e55fd085a2..c0f149e3137 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/AuthenticationResourceHelper.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/AuthenticationResourceHelper.cs @@ -2,12 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +using CoreWCF.IdentityModel.Selectors; +using CoreWCF.IdentityModel.Tokens; +using CoreWCF.Security; +#else using System; using System.IdentityModel.Selectors; using System.IdentityModel.Tokens; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif namespace WcfService { @@ -101,6 +108,7 @@ public override string GetRealm(ref Message message) private class SideChannelHeaderUserNamePasswordValidator : UserNamePasswordValidator { + [Obsolete] public override void Validate(string userName, string password) { char[] usernameArr = userName.ToCharArray(); diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicAuthTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicAuthTestServiceHost.cs index 7d7d5f01b6e..ba3b0b13211 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicAuthTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicAuthTestServiceHost.cs @@ -2,9 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpService1Host.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpService1Host.cs index 182f7d5b8b9..50a696f20c7 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpService1Host.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpService1Host.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpSoapTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpSoapTestServiceHost.cs index a616f682ba8..ce754b333a4 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpSoapTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpSoapTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpTestServiceHost.4.4.0.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpTestServiceHost.4.4.0.cs index d1661221a90..314a7791178 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpTestServiceHost.4.4.0.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpTestServiceHost.4.4.0.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpTestServiceHost.cs index 4e5384e60d1..31d8b603519 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpXmlSerFormatAttrServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpXmlSerFormatAttrServiceHost.cs index 0a8a497b6c3..3a73678a6ab 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpXmlSerFormatAttrServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpXmlSerFormatAttrServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsBindingTransportWithMessageCredentialsCertTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsBindingTransportWithMessageCredentialsCertTestServiceHost.cs index 80564cec68d..a1b0d675394 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsBindingTransportWithMessageCredentialsCertTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsBindingTransportWithMessageCredentialsCertTestServiceHost.cs @@ -2,10 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTestServiceHost.cs index 5e83c6bb0d6..b071ed0a6f8 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTransportSecurityMessageCredentialsCertTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTransportSecurityMessageCredentialsCertTestServiceHost.cs index 6f64fb6dc9d..313c132c3b9 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTransportSecurityMessageCredentialsCertTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTransportSecurityMessageCredentialsCertTestServiceHost.cs @@ -2,10 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTransportSecurityMessageCredentialsUserNameTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTransportSecurityMessageCredentialsUserNameTestServiceHost.cs index f367b965530..3efc412b4b3 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTransportSecurityMessageCredentialsUserNameTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/BasicHttpsTransportSecurityMessageCredentialsUserNameTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ChannelExtensibilityTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ChannelExtensibilityTestServiceHost.cs deleted file mode 100644 index 683eb15627e..00000000000 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ChannelExtensibilityTestServiceHost.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.Samples.MessageInterceptor; -using System; -using System.ServiceModel.Channels; - -namespace WcfService -{ - [TestServiceDefinition(Schema = ServiceSchema.HTTP, BasePath = "ChannelExtensibility.svc")] - public class ChannelExtensibilityServiceHost : TestServiceHostBase - { - protected override string Address { get { return "ChannelExtensibility"; } } - - protected override Binding GetBinding() - { - return new CustomBinding(new InterceptingBindingElement(new DroppingServerInterceptor()), new HttpTransportBindingElement()); - } - - public ChannelExtensibilityServiceHost(params Uri[] baseAddresses) - : base(typeof(WcfChannelExtensiblityService), baseAddresses) - { - } - } -} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextEncoderBufferedServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextEncoderBufferedServiceHost.cs index 985318c166b..acc1691923e 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextEncoderBufferedServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextEncoderBufferedServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextEncoderStreamedServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextEncoderStreamedServiceHost.cs index 092643aaef6..b8b61db2562 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextEncoderStreamedServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextEncoderStreamedServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageBindingElement.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageBindingElement.cs index e9f1a7793ac..d53bb7e67ad 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageBindingElement.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageBindingElement.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Xml; namespace WcfService @@ -40,7 +44,7 @@ public CustomTextMessageBindingElement(string encoding, string mediaType, Messag } public CustomTextMessageBindingElement(string encoding, string mediaType) - : this(encoding, mediaType, System.ServiceModel.Channels.MessageVersion.Soap12WSAddressing10) + : this(encoding, mediaType, MessageVersion.Soap12WSAddressing10) { } @@ -116,6 +120,7 @@ public override BindingElement Clone() return new CustomTextMessageBindingElement(this); } +#if !NET public override IChannelFactory BuildChannelFactory(BindingContext context) { if (context == null) @@ -150,6 +155,7 @@ public override bool CanBuildChannelListener(BindingContext context) context.BindingParameters.Add(this); return context.CanBuildInnerChannelListener(); } +#endif public override T GetProperty(BindingContext context) { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageEncoder.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageEncoder.cs index e4ee23c197e..418f30ba16c 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageEncoder.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageEncoder.cs @@ -2,15 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.IO; using System.ServiceModel.Channels; +#endif using System.Text; using System.Xml; namespace WcfService { - internal class CustomTextMessageEncoder : System.ServiceModel.Channels.MessageEncoder + internal class CustomTextMessageEncoder : MessageEncoder { private CustomTextMessageEncoderFactory _factory; private XmlWriterSettings _writerSettings; @@ -50,6 +54,12 @@ public override MessageVersion MessageVersion } } +#if NET + public override Message ReadMessage(ArraySegment buffer, BufferManager bufferManager, string contentType) => throw new NotImplementedException(); + public override Task ReadMessageAsync(Stream stream, int maxSizeOfHeaders, string contentType) => throw new NotImplementedException(); + public override ArraySegment WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) => throw new NotImplementedException(); + public override Task WriteMessageAsync(Message message, Stream stream) => throw new NotImplementedException(); +#else public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType) { XmlReader reader = XmlReader.Create(stream); @@ -102,5 +112,6 @@ public override ArraySegment WriteMessage(Message message, int maxMessageS ArraySegment byteArray = new ArraySegment(totalBytes, messageOffset, messageLength); return byteArray; } +#endif } } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageEncoderFactory.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageEncoderFactory.cs index 942348613c2..631dc9c32ec 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageEncoderFactory.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/CustomTextMessageEncoderFactory.cs @@ -2,13 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System.ServiceModel.Channels; +#endif namespace WcfService { internal class CustomTextMessageEncoderFactory : MessageEncoderFactory { - private System.ServiceModel.Channels.MessageEncoder _encoder; + private MessageEncoder _encoder; private MessageVersion _version; private string _mediaType; private string _charSet; @@ -21,7 +25,7 @@ internal CustomTextMessageEncoderFactory(string mediaType, string charSet, Messa _encoder = new CustomTextMessageEncoder(this); } - public override System.ServiceModel.Channels.MessageEncoder Encoder + public override MessageEncoder Encoder { get { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DataContractResolverTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DataContractResolverTestServiceHost.cs index d44199820da..f93f81517f4 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DataContractResolverTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DataContractResolverTestServiceHost.cs @@ -1,8 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Description; +#else using System; using System.Linq; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DefaultCustomHttpTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DefaultCustomHttpTestServiceHost.cs index 1aff2807d75..aa866476050 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DefaultCustomHttpTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DefaultCustomHttpTestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs index 0cee0c50ac0..934d57b4d8a 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs @@ -2,11 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -17,7 +23,7 @@ public class DuplexTestServiceHost : TestServiceHostBase protected override Binding GetBinding() { - return new NetTcpBinding(SecurityMode.None) { PortSharingEnabled = false }; + return new NetTcpBinding(SecurityMode.None); } public DuplexTestServiceHost(params Uri[] baseAddresses) @@ -33,7 +39,7 @@ public class DuplexCallbackTestServiceHost : TestServiceHostBase ToApm(this Task task, AsyncCallb } } } +#endif diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/FederationSTSServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/FederationSTSServiceHost.cs index 357248f031e..3a8c049e75c 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/FederationSTSServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/FederationSTSServiceHost.cs @@ -2,15 +2,23 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.IdentityModel.Tokens; +using CoreWCF.Security; +using Microsoft.Extensions.Hosting.Internal; +#else using System; using System.Collections.Generic; using System.IdentityModel.Configuration; using System.IdentityModel.Tokens; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.Web.Hosting; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/ReturnX509SubjectNameOrRSAIssuerNameRegistry.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/ReturnX509SubjectNameOrRSAIssuerNameRegistry.cs index ce609e3f9df..1d4fe1e31e2 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/ReturnX509SubjectNameOrRSAIssuerNameRegistry.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/ReturnX509SubjectNameOrRSAIssuerNameRegistry.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.IdentityModel.Tokens; +#else using System.IdentityModel.Tokens; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/SelfHostSecurityTokenService.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/SelfHostSecurityTokenService.cs index 80ca93c1073..c314d7d3631 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/SelfHostSecurityTokenService.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Federation/SelfHostSecurityTokenService.cs @@ -2,12 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.IdentityModel; using System.IdentityModel.Configuration; using System.IdentityModel.Protocols.WSTrust; -using System.Security.Claims; using System.ServiceModel; +#endif +using System.Security.Claims; namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpBinaryTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpBinaryTestServiceHost.cs index 9db13ee3029..1beff8574cf 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpBinaryTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpBinaryTestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpDigestNoDomainTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpDigestNoDomainTestServiceHost.cs index aab80d3e2d4..6531392e1d8 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpDigestNoDomainTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpDigestNoDomainTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11TestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11TestServiceHost.cs index 08f52f5d5dd..72f034a7ee5 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11TestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11TestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11WSA10TestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11WSA10TestServiceHost.cs index ba805d25464..7d1d853c304 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11WSA10TestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11WSA10TestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11WSA2004ServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11WSA2004ServiceHost.cs index 48256abb521..f741980957b 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11WSA2004ServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap11WSA2004ServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12TestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12TestServiceHost.cs index 5ff43cb74b1..6bac8ec4b53 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12TestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12TestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12WSA2004ServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12WSA2004ServiceHost.cs index 113d2a443d2..c1781d7a630 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12WSA2004ServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12WSA2004ServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12WSANoneTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12WSANoneTestServiceHost.cs index 181e14e7ebd..f2f23f31dce 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12WSANoneTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpSoap12WSANoneTestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpWindowsTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpWindowsTestServiceHost.cs index 38b534005e0..6c7b7199c73 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpWindowsTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpWindowsTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsCertificateValidationChainTrustTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsCertificateValidationChainTrustTestServiceHost.cs index 813bb02b0d1..20a8dc14768 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsCertificateValidationChainTrustTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsCertificateValidationChainTrustTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -26,12 +31,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - certThumprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + this.Credentials.ServiceCertificate.Certificate = cert; } public HttpsCertificateValidationChainTrustTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsCertificateValidationPeerTrustTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsCertificateValidationPeerTrustTestServiceHost.cs index fa72da7554a..c04c8d75dda 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsCertificateValidationPeerTrustTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsCertificateValidationPeerTrustTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -26,12 +31,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.TrustedPeople, StoreLocation.LocalMachine, "WCF Bridge - UserPeerTrustCertificateResource").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.TrustedPeople, - X509FindType.FindByThumbprint, - certThumprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.TrustedPeople, StoreLocation.LocalMachine, "WCF Bridge - UserPeerTrustCertificateResource"); + this.Credentials.ServiceCertificate.Certificate = cert; } public HttpsCertificateValidationPeerTrustTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsClientCertificateTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsClientCertificateTestServiceHost.cs index 3f5889e11b9..df7aa1003d6 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsClientCertificateTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsClientCertificateTestServiceHost.cs @@ -2,11 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsDigestTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsDigestTestServiceHost.cs index 472968658f7..fe36593532a 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsDigestTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsDigestTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsNtlmTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsNtlmTestServiceHost.cs index e4eea6ebfcf..0d6a7b0b80e 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsNtlmTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsNtlmTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsSoap11TestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsSoap11TestServiceHost.cs index ab1bd33e236..a10b1da2926 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsSoap11TestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsSoap11TestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsSoap12TestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsSoap12TestServiceHost.cs index dcc2a947904..64c9f849966 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsSoap12TestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsSoap12TestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif using System.Text; namespace WcfService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsTransportSecurityMessageCredentialsCertTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsTransportSecurityMessageCredentialsCertTestServiceHost.cs index 000ab1a0e5e..621ac899b0d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsTransportSecurityMessageCredentialsCertTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsTransportSecurityMessageCredentialsCertTestServiceHost.cs @@ -2,11 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsTransportSecurityMessageCredentialsUsernameTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsTransportSecurityMessageCredentialsUsernameTestServiceHost.cs index 4e33eb0e070..1dd0b392b54 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsTransportSecurityMessageCredentialsUsernameTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsTransportSecurityMessageCredentialsUsernameTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsWindowsTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsWindowsTestServiceHost.cs index 8606aac0149..d5eb20c8c84 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsWindowsTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsWindowsTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpTestServiceHost.cs index 2569c367bcb..7465833fa89 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpsTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpsTestServiceHost.cs index e72615a819c..3c65e550606 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpsTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpsTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionDuplexTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionDuplexTestServiceHost.cs index 213164e1b9d..04170580ff0 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionDuplexTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionDuplexTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionOneWayTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionOneWayTestServiceHost.cs index c95b7861fae..4507d468a22 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionOneWayTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionOneWayTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionTestServiceHost.cs index 8d1dc58590a..089ef617d75 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ReliableSessionTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/RequestLoggingServiceBehavior.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/RequestLoggingServiceBehavior.cs index ae5dc51e38e..a71215546d3 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/RequestLoggingServiceBehavior.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/RequestLoggingServiceBehavior.cs @@ -4,12 +4,19 @@ // +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Description; +using CoreWCF.Dispatcher; +#else using System; -using System.Collections.ObjectModel; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; +#endif +using System.Collections.ObjectModel; using System.Text; namespace WcfService @@ -115,6 +122,7 @@ public RequestLoggingAuthenticationWrapper(RequestLoggingServiceBehavior request _parent = parent; } + [Obsolete] public override bool CheckAccess(OperationContext operationContext, ref Message message) { bool success = false; @@ -137,4 +145,4 @@ public override bool CheckAccess(OperationContext operationContext, ref Message } } } -} \ No newline at end of file +} diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Saml2IssuedTokenTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Saml2IssuedTokenTestServiceHost.cs index ff095efafd0..ab82ea5734b 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Saml2IssuedTokenTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/Saml2IssuedTokenTestServiceHost.cs @@ -2,14 +2,21 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.IdentityModel.Tokens; +using CoreWCF.Security; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.IdentityModel.Tokens; using System.Collections.Generic; using System.Diagnostics; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ServiceContractAsyncTestServiceHosts.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ServiceContractAsyncTestServiceHosts.cs index 37b0fcf87fc..35ab3b531a7 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ServiceContractAsyncTestServiceHosts.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/ServiceContractAsyncTestServiceHosts.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateValidationPeerTrustTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateValidationPeerTrustTestServiceHost.cs index 728f53f4ee3..95d3360c17f 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateValidationPeerTrustTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateValidationPeerTrustTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -16,7 +21,7 @@ public class TcpCertificateValidationPeerTrustTestServiceHost : TestServiceHostB protected override Binding GetBinding() { - NetTcpBinding binding = new NetTcpBinding() { PortSharingEnabled = false }; + NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; @@ -27,12 +32,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.TrustedPeople, StoreLocation.LocalMachine, "WCF Bridge - UserPeerTrustCertificateResource").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.TrustedPeople, - X509FindType.FindByThumbprint, - certThumprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.TrustedPeople, StoreLocation.LocalMachine, "WCF Bridge - UserPeerTrustCertificateResource"); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpCertificateValidationPeerTrustTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithServerAltNameTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithServerAltNameTestServiceHost.cs index 7a3d9a8ac18..9610db22bed 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithServerAltNameTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithServerAltNameTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -16,7 +21,7 @@ public class TcpCertificateWithServerAltNameTestServiceHost : TestServiceHostBas protected override Binding GetBinding() { - NetTcpBinding binding = new NetTcpBinding() { PortSharingEnabled = false }; + NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; @@ -27,12 +32,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithServerAltNameResource").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - certThumprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithServerAltNameResource"); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpCertificateWithServerAltNameTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameDomainNameTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameDomainNameTestServiceHost.cs index 06e54f3edd2..acc659e309f 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameDomainNameTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameDomainNameTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -16,7 +21,7 @@ public class TcpCertificateWithSubjectCanonicalNameDomainNameTestServiceHost : T protected override Binding GetBinding() { - NetTcpBinding binding = new NetTcpBinding() { PortSharingEnabled = false }; + NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; @@ -27,12 +32,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithSubjectCanonicalNameDomainNameResource").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - certThumprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithSubjectCanonicalNameDomainNameResource"); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpCertificateWithSubjectCanonicalNameDomainNameTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameFqdnTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameFqdnTestServiceHost.cs index 156b6482110..36febed16cf 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameFqdnTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameFqdnTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -17,7 +22,7 @@ public class TcpCertificateWithSubjectCanonicalNameFqdnTestServiceHost : TestSer protected override Binding GetBinding() { - NetTcpBinding binding = new NetTcpBinding() { PortSharingEnabled = false }; + NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; @@ -28,14 +33,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - { - string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithSubjectCanonicalNameFqdnResource").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - certThumprint); - } + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithSubjectCanonicalNameFqdnResource"); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpCertificateWithSubjectCanonicalNameFqdnTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost.cs index e67da3576bf..6cbdb902cbc 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -16,7 +21,7 @@ public class TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost : Te protected override Binding GetBinding() { - NetTcpBinding binding = new NetTcpBinding() { PortSharingEnabled = false }; + NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; @@ -27,12 +32,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithSubjectCanonicalNameLocalhostResource").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - certThumprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithSubjectCanonicalNameLocalhostResource"); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpDefaultResourceTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpDefaultResourceTestServiceHost.cs index b84f4a42a34..f1d8a29fb9b 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpDefaultResourceTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpDefaultResourceTestServiceHost.cs @@ -2,11 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; using System.Web.Hosting; +#endif namespace WcfService { @@ -27,7 +32,7 @@ protected override IList GetBindings() private Binding GetNetTcpBinding() { - return new NetTcpBinding() { PortSharingEnabled = false, Name = "tcp-default" }; + return new NetTcpBinding() { Name = "tcp-default" }; } private Binding GetNetNamedPipeBinding() diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpExpiredServerCertTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpExpiredServerCertTestServiceHost.cs index 63b3c0a4acb..806cbc6a73a 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpExpiredServerCertTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpExpiredServerCertTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -16,7 +21,7 @@ public class TcpExpiredServerCertTestServiceHost : TestServiceHostBase GetBindings() private Binding GetNetTcpBinding() { - return new NetTcpBinding(SecurityMode.None) { PortSharingEnabled = false , Name = "tcp-nosecurity" }; + return new NetTcpBinding(SecurityMode.None) { Name = "tcp-nosecurity" }; } private Binding GetNetNamedPipeBinding() diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpNoSecurityTextTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpNoSecurityTextTestServiceHost.cs index 7cc94f70f38..f58c399300b 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpNoSecurityTextTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpNoSecurityTextTestServiceHost.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +#else using System; using System.ServiceModel.Channels; +#endif namespace WcfService { @@ -14,7 +18,7 @@ public class TcpNoSecurityTextTestServiceHost : TestServiceHostBase protected override Binding GetBinding() { - return new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement() { PortSharingEnabled = false }); + return new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement()); } public TcpNoSecurityTextTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpRevokedServerCertTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpRevokedServerCertTestServiceHost.cs index 9c4c29368bd..a813cbcb54e 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpRevokedServerCertTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpRevokedServerCertTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -16,7 +21,7 @@ public class TcpRevokedServerCertTestServiceHost : TestServiceHostBase protected override Binding GetBinding() { - return new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11WSAddressing10, Encoding.UTF8), new TcpTransportBindingElement() { PortSharingEnabled = false }); + return new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11WSAddressing10, Encoding.UTF8), new TcpTransportBindingElement()); } public TcpSoap11WSA10TestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpStreamedNoSecurityTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpStreamedNoSecurityTestServiceHost.cs index 7fc2719b087..a8e79f255d5 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpStreamedNoSecurityTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpStreamedNoSecurityTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { @@ -17,7 +22,6 @@ protected override Binding GetBinding() { return new NetTcpBinding(SecurityMode.None) { - PortSharingEnabled = false, TransferMode = TransferMode.Streamed }; } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityMessageCredentialsCertTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityMessageCredentialsCertTestServiceHost.cs index 5bcfe1d53c4..a08ec4e4e74 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityMessageCredentialsCertTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityMessageCredentialsCertTestServiceHost.cs @@ -2,11 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -30,11 +36,8 @@ protected override void ApplyConfiguration() this.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom; this.Credentials.ClientCertificate.Authentication.CustomCertificateValidator = new MyX509CertificateValidator("DO_NOT_TRUST_WcfBridgeRootCA"); - string thumbprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager").Thumbprint; - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - thumbprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpTransportSecurityMessageCredentialsCertTestServiceHost(params Uri[] baseAddresses) : base(typeof(WcfService), baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityMessageCredentialsUsernameTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityMessageCredentialsUsernameTestServiceHost.cs index 5f94e22d613..a03aafb07d8 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityMessageCredentialsUsernameTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityMessageCredentialsUsernameTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -28,11 +33,8 @@ protected override void ApplyConfiguration() base.ApplyConfiguration(); AuthenticationResourceHelper.ConfigureServiceHostUserNameAuth(this); - string thumbprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager").Thumbprint; - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - thumbprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpTransportSecurityMessageCredentialsUserNameTestServiceHost(params Uri[] baseAddresses) : base(typeof(WcfService), baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecuritySslClientCredentialTypeCertificate.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecuritySslClientCredentialTypeCertificate.cs index 5304c2d0048..25ddc69b924 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecuritySslClientCredentialTypeCertificate.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecuritySslClientCredentialTypeCertificate.cs @@ -2,11 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -26,13 +32,10 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); // Ensure the https certificate is installed before this endpoint resource is used - string thumbprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager").Thumbprint; + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); this.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - thumbprint); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpTransportSecuritySslClientCredentialTypeCertificateTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecuritySslCustomCertValidationTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecuritySslCustomCertValidationTestServiceHost.cs index b313748e71d..57ea4655afd 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecuritySslCustomCertValidationTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecuritySslCustomCertValidationTestServiceHost.cs @@ -2,11 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -26,14 +32,11 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - string thumbprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager").Thumbprint; + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); this.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom; this.Credentials.ClientCertificate.Authentication.CustomCertificateValidator = new MyX509CertificateValidator("DO_NOT_TRUST_WcfBridgeRootCA"); - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - thumbprint); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpTransportSecuritySslCustomCertValidationTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityStreamedTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityStreamedTestServiceHost.cs index 3f9ef5cb757..f6513f34c1c 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityStreamedTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityStreamedTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { @@ -17,7 +22,6 @@ protected override Binding GetBinding() { return new NetTcpBinding(SecurityMode.Transport) { - PortSharingEnabled = false, TransferMode = TransferMode.Streamed }; } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityWithSslTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityWithSslTestServiceHost.cs index 913f7b6ffa2..5f83a1d87e9 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityWithSslTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpTransportSecurityWithSslTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +using CoreWCF.Security; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel.Channels; using System.ServiceModel.Security; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -27,12 +32,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); { - string thumbprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - thumbprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + this.Credentials.ServiceCertificate.Certificate = cert; this.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpVerifyDNSTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpVerifyDNSTestServiceHost.cs index 107eb8b83fc..009011299e9 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpVerifyDNSTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpVerifyDNSTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; -using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; +#endif +using System.Security.Cryptography.X509Certificates; namespace WcfService { @@ -15,7 +20,7 @@ public class TcpVerifyDNSTestServiceHost : TestServiceHostBase protected override string Address { get { return "tcp-VerifyDNS"; } } protected override Binding GetBinding() { - NetTcpBinding binding = new NetTcpBinding() { PortSharingEnabled = false }; + NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; @@ -26,12 +31,8 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); - string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager").Thumbprint; - - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - certThumprint); + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + this.Credentials.ServiceCertificate.Certificate = cert; } public TcpVerifyDNSTestServiceHost(params Uri[] baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestHostWebServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestHostWebServiceHost.cs index c1f58bcdb3a..585faba21e2 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestHostWebServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestHostWebServiceHost.cs @@ -2,10 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +#else using System; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestServiceHostBase.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestServiceHostBase.cs index e4921609dd6..ab1f131f483 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestServiceHostBase.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestServiceHostBase.cs @@ -2,12 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF.Channels; +using CoreWCF.Description; +#else using System; using System.Collections; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; +#endif namespace WcfService { @@ -30,12 +35,13 @@ protected virtual IList GetBindings() public TestServiceHostBase(Type serviceType, params Uri[] baseAddresses) : base(serviceType, baseAddresses) { - foreach(var binding in GetBindings()) + foreach (var binding in GetBindings()) { AddServiceEndpoint(typeof(ContractType), binding, binding.Name == EmptyAddress ? "" : binding.Name); } } +#if !NET //Overriding ApplyConfiguration() allows us to //alter the ServiceDescription prior to opening //the service host. @@ -91,6 +97,7 @@ protected override void ApplyConfiguration() } } } +#endif } public abstract class TestServiceHostBase : TestServiceHostBase @@ -98,7 +105,7 @@ public abstract class TestServiceHostBase : TestSe public TestServiceHostBase(Type serviceType, params Uri[] baseAddresses) : base(serviceType, baseAddresses) { - ServiceEndpoint endpoint2 = this.AddServiceEndpoint(typeof(ContractType2), GetBinding(), Address); + AddServiceEndpoint(typeof(ContractType2), GetBinding(), Address); } } } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/UnderstoodHeadersServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/UnderstoodHeadersServiceHost.cs index d99a7a421a2..6b53eb8707e 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/UnderstoodHeadersServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/UnderstoodHeadersServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WSHttpBindingTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WSHttpBindingTestServiceHost.cs index f4ef56e8149..8a501fb9713 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WSHttpBindingTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WSHttpBindingTestServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WcfDecompServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WcfDecompServiceHost.cs index 55a2b3afb96..7863d7d3ea7 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WcfDecompServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WcfDecompServiceHost.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WebSocketTestServiceHosts.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WebSocketTestServiceHosts.cs index 968c4bf7ae0..9cf89ff9158 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WebSocketTestServiceHosts.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WebSocketTestServiceHosts.cs @@ -2,10 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/XmlSFAttributeTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/XmlSFAttributeTestServiceHost.cs index bae867fc51d..a42cb494b9e 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/XmlSFAttributeTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/XmlSFAttributeTestServiceHost.cs @@ -2,9 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else using System; using System.ServiceModel; using System.ServiceModel.Channels; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/XmlSerializerRpcEncWithMessageHeadersServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/XmlSerializerRpcEncWithMessageHeadersServiceHost.cs index 432aa7a9751..d78dcc71d5d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/XmlSerializerRpcEncWithMessageHeadersServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/XmlSerializerRpcEncWithMessageHeadersServiceHost.cs @@ -1,10 +1,19 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#if NET +using CoreWCF; +using CoreWCF.Channels; +#else +using System; using System.Collections.Generic; using System.Linq; using System.ServiceModel; using System.ServiceModel.Channels; using System.Text; using System.Threading.Tasks; +#endif namespace WcfService { diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Program.cs b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Program.cs new file mode 100644 index 00000000000..be239f719aa --- /dev/null +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Program.cs @@ -0,0 +1,88 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.InteropServices; +using WcfService; + +namespace SelfHostedWCFService +{ + public class Parameters + { + public const string ServiceBootstrap = "bootstrap"; + } + + public class SelfHostedWCFService + { + private static bool s_serviceBootstrap = false; + + public static async Task Main(string[] args) + { + ParseArgs(args); + + if (s_serviceBootstrap) + { + await ServiceHostHelper.ServiceBootstrap(); + Environment.Exit(1); + } + + Console.WriteLine("Installing certificates..."); + string testserverbase = string.Empty; + TimeSpan validatePeriod = TimeSpan.FromDays(1); + string crlFileLocation = "c:\\WCFTest\\test.crl"; + + CertificateGeneratorLibrary.SetupCerts(testserverbase, validatePeriod, crlFileLocation); + + Console.WriteLine("Starting services..."); + await TestDefinitionHelper.StartHosts(); + + Console.WriteLine("All services started."); + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + do + { + Console.WriteLine("Type to terminate the self service Host."); + string input = Console.ReadLine(); + if (string.Compare(input, "exit", true) == 0) + { + return; + } + } while (true); + } + else + { + //Linux and MacOS + Console.WriteLine("Use Shutdown endpoint to terminate the self service Host."); + Console.WriteLine("http://localhost:8081/TestHost.svc/shutdown"); + + Thread.Sleep(Timeout.Infinite); + } + } + + private static bool ParseArgs(string[] args) + { + foreach (string s in args) + { + string[] p = s.Split(new char[] { ':' }, count: 2); + if (p.Length != 2) + { + continue; + } + + switch (p[0].ToLower()) + { + case Parameters.ServiceBootstrap: + bool.TryParse(p[1], out s_serviceBootstrap); + break; + default: + Console.WriteLine("unknown argument: " + s); + continue; + } + } + + return true; + } + + } +} diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Properties/launchSettings.json b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Properties/launchSettings.json new file mode 100644 index 00000000000..a8fe0e498a0 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "SelfHostedCoreWCFService": { + "commandName": "Project", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:44285;http://localhost:8081" + } + } +} diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj new file mode 100644 index 00000000000..422f7a554ed --- /dev/null +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj @@ -0,0 +1,82 @@ + + + net8.0 + true + false + false + + + + + + + + + + + + + + + + true + IIS/%(RecursiveDir)%(Filename)%(Extension) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Web.config + + + + + + diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.sln b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.sln new file mode 100644 index 00000000000..cd95c275115 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.32916.344 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SelfHostedCoreWCFService", "SelfHostedCoreWCFService.csproj", "{19D41124-E785-44E4-9B7A-F75B6D21A7CD}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CertificateGeneratorLibrary", "..\CertificateGenerator\CertificateGeneratorLibrary\CertificateGeneratorLibrary.csproj", "{314D8E66-225C-495E-AAB9-93966B825BEA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {19D41124-E785-44E4-9B7A-F75B6D21A7CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19D41124-E785-44E4-9B7A-F75B6D21A7CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19D41124-E785-44E4-9B7A-F75B6D21A7CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19D41124-E785-44E4-9B7A-F75B6D21A7CD}.Release|Any CPU.Build.0 = Release|Any CPU + {314D8E66-225C-495E-AAB9-93966B825BEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {314D8E66-225C-495E-AAB9-93966B825BEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {314D8E66-225C-495E-AAB9-93966B825BEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {314D8E66-225C-495E-AAB9-93966B825BEA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {38C67964-0504-4D3C-A5A0-2CD0C9A2E018} + EndGlobalSection +EndGlobal diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/appsettings.Development.json b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/appsettings.Development.json new file mode 100644 index 00000000000..0c208ae9181 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/appsettings.json b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/appsettings.json new file mode 100644 index 00000000000..10f68b8c8b4 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/src/System.Private.ServiceModel/tools/SelfHostedWcfService/Program.cs b/src/System.Private.ServiceModel/tools/SelfHostedWcfService/Program.cs index 248c04b17e6..a4d9c7bb081 100644 --- a/src/System.Private.ServiceModel/tools/SelfHostedWcfService/Program.cs +++ b/src/System.Private.ServiceModel/tools/SelfHostedWcfService/Program.cs @@ -14,7 +14,7 @@ public class SelfHostedWCFService { private static int s_httpPort = 8081; private static int s_httpsPort = 44285; - private static int s_tcpPort = 809; + private static int s_tcpPort = 8808; private static int s_websocketPort = 8083; private static int s_websocketsPort = 8084; diff --git a/src/System.Private.ServiceModel/tools/SelfHostedWcfService/SelfHostedWCFService.csproj b/src/System.Private.ServiceModel/tools/SelfHostedWcfService/SelfHostedWCFService.csproj index 9c00c33199b..a9beca17758 100644 --- a/src/System.Private.ServiceModel/tools/SelfHostedWcfService/SelfHostedWCFService.csproj +++ b/src/System.Private.ServiceModel/tools/SelfHostedWcfService/SelfHostedWCFService.csproj @@ -26,4 +26,7 @@ Web.config + + + diff --git a/src/System.Private.ServiceModel/tools/SelfHostedWcfService/SelfHostedWCFService.sln b/src/System.Private.ServiceModel/tools/SelfHostedWcfService/SelfHostedWCFService.sln index 44236df8c0f..273a7919d17 100644 --- a/src/System.Private.ServiceModel/tools/SelfHostedWcfService/SelfHostedWCFService.sln +++ b/src/System.Private.ServiceModel/tools/SelfHostedWcfService/SelfHostedWCFService.sln @@ -1,9 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28803.202 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34707.107 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfHostedWCFService", "SelfHostedWCFService.csproj", "{4E7F9B04-79A4-43F5-BD3C-781AA57DDB52}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SelfHostedWCFService", "SelfHostedWCFService.csproj", "{4E7F9B04-79A4-43F5-BD3C-781AA57DDB52}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CertificateGeneratorLibrary", "..\CertificateGenerator\CertificateGeneratorLibrary\CertificateGeneratorLibrary.csproj", "{EF492133-7146-4A3F-B07B-80C3304D4B6B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {4E7F9B04-79A4-43F5-BD3C-781AA57DDB52}.Debug|Any CPU.Build.0 = Release|Any CPU {4E7F9B04-79A4-43F5-BD3C-781AA57DDB52}.Release|Any CPU.ActiveCfg = Release|Any CPU {4E7F9B04-79A4-43F5-BD3C-781AA57DDB52}.Release|Any CPU.Build.0 = Release|Any CPU + {EF492133-7146-4A3F-B07B-80C3304D4B6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF492133-7146-4A3F-B07B-80C3304D4B6B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF492133-7146-4A3F-B07B-80C3304D4B6B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF492133-7146-4A3F-B07B-80C3304D4B6B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/System.Private.ServiceModel/tools/scripts/OpenFirewallPorts.cmd b/src/System.Private.ServiceModel/tools/scripts/OpenFirewallPorts.cmd index f3bbc4dbe60..f2c7789fdd8 100644 --- a/src/System.Private.ServiceModel/tools/scripts/OpenFirewallPorts.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/OpenFirewallPorts.cmd @@ -33,7 +33,7 @@ if NOT [%__EXITCODE%]==[0] ( goto :done ) -netsh advfirewall firewall add rule name="_WCF Test Server PortTcp" dir=in action=allow profile=any localport=809 protocol=tcp +netsh advfirewall firewall add rule name="_WCF Test Server PortTcp" dir=in action=allow profile=any localport=8808 protocol=tcp set __EXITCODE=%ERRORLEVEL% if NOT [%__EXITCODE%]==[0] ( echo Error: error adding rule name _WCF Test Server PortTcp From dd2e1d270349515d146fad3be65abdface0a9d99 Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Wed, 17 Jul 2024 21:02:47 +0300 Subject: [PATCH 02/12] update MacOS cert store --- azure-pipelines-arcade-PR.yml | 8 ++--- azure-pipelines-arcade.yml | 5 ++- eng/SendToHelix.proj | 12 +++---- .../CertificateGenerator.cs | 31 +++++++++++++++++-- .../CertificateGeneratorLibrary.cs | 7 +++-- .../CertificateHelper.cs | 15 ++++++--- .../CertificateManager.cs | 7 +++-- .../IISHostedWcfService/App_code/TestHost.cs | 10 ++++-- 8 files changed, 69 insertions(+), 26 deletions(-) diff --git a/azure-pipelines-arcade-PR.yml b/azure-pipelines-arcade-PR.yml index f862d72e6ea..40efaf079a5 100644 --- a/azure-pipelines-arcade-PR.yml +++ b/azure-pipelines-arcade-PR.yml @@ -32,7 +32,7 @@ variables: - name: _RunAsInternal value: false - name: _RunWithCoreWcfService - value: true + value: false - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - name: _RunAsPublic @@ -128,6 +128,7 @@ stages: -projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=Windows + /p:RunWithCoreWcfService=$(_RunWithCoreWcfService) /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog displayName: Windows - Run Helix Tests env: @@ -136,7 +137,6 @@ stages: XUnitWorkItemTimeout: $(_xUnitWorkItemTimeout) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) - RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: true # Only build and test Linux in PR and CI builds. @@ -190,6 +190,7 @@ stages: --projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=Linux + /p:RunWithCoreWcfService=$(_RunWithCoreWcfService) /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog displayName: Linux - Run Helix Tests env: @@ -197,7 +198,6 @@ stages: ServiceHost: $(_serviceUri) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) - RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: false # Only build and test MacOS in PR and CI builds. @@ -250,6 +250,7 @@ stages: -projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=MacOS + /p:RunWithCoreWcfService=$(_RunWithCoreWcfService) /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog displayName: MacOS - Run Helix Tests env: @@ -257,5 +258,4 @@ stages: ServiceHost: $(_serviceUri) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) - RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: false \ No newline at end of file diff --git a/azure-pipelines-arcade.yml b/azure-pipelines-arcade.yml index 30629f24f19..93608eb37b4 100644 --- a/azure-pipelines-arcade.yml +++ b/azure-pipelines-arcade.yml @@ -25,7 +25,7 @@ variables: - name: _RunAsInternal value: true - name: _RunWithCoreWcfService - value: true + value: false - group: DotNet-Wcf-SDLValidation-Params resources: repositories: @@ -97,7 +97,7 @@ extends: clean: true - script: eng\common\cibuild.cmd -configuration $(_BuildConfig) -preparemachine $(_InternalBuildArgs) $(_TestArgs) /p:Test=false displayName: Windows Build / Publish - - powershell: eng\common\build.ps1 -configuration $(_BuildConfig) -preparemachine -ci -test -integrationTest -projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=Windows /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog + - powershell: eng\common\build.ps1 -configuration $(_BuildConfig) -preparemachine -ci -test -integrationTest -projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=Windows /p:RunWithCoreWcfService=$(_RunWithCoreWcfService) /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog displayName: Windows - Run Helix Tests env: SYSTEM_ACCESSTOKEN: $(System.AccessToken) @@ -105,7 +105,6 @@ extends: XUnitWorkItemTimeout: $(_xUnitWorkItemTimeout) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) - RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: true - ${{ if eq(variables._RunAsInternal, True) }}: - template: /eng/common/templates-official/post-build/post-build.yml@self diff --git a/eng/SendToHelix.proj b/eng/SendToHelix.proj index 78ad194a2d6..a2ab9ba081f 100644 --- a/eng/SendToHelix.proj +++ b/eng/SendToHelix.proj @@ -16,7 +16,7 @@ $(AGENT_JOBNAME) true - + @@ -71,15 +71,15 @@ - false + false - - + + $(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);set PATH=%HELIX_CORRELATION_PAYLOAD%\dotnet-cli%3B%PATH% $(HelixPreCommands);set DOTNET_ROOT=%HELIX_CORRELATION_PAYLOAD%\dotnet-cli;set DOTNET_CLI_TELEMETRY_OPTOUT=1 @@ -89,7 +89,7 @@ $(HelixPreCommands);%HELIX_CORRELATION_PAYLOAD%\SelfHostedCoreWCFService\$(Configuration)\net8.0\SelfHostedCoreWCFService bootstrap:true - + $(HelixPreCommands);export PATH=$HELIX_CORRELATION_PAYLOAD/dotnet-cli:$PATH $(HelixPreCommands);export DOTNET_ROOT=$HELIX_CORRELATION_PAYLOAD/dotnet-cli;export DOTNET_CLI_TELEMETRY_OPTOUT=1 $(HelixPreCommands);export DOTNET_CLI_HOME=$HELIX_WORKITEM_ROOT/.dotnet diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGenerator.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGenerator.cs index 5680c8a0e46..3c18c6551f3 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGenerator.cs +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGenerator.cs @@ -452,7 +452,7 @@ private X509CertificateContainer CreateCertificate(bool isAuthority, bool isMach container.Pfx = stream.ToArray(); } - X509Certificate2 outputCert; + X509Certificate2 outputCert = null; if (isAuthority) { @@ -463,7 +463,34 @@ private X509CertificateContainer CreateCertificate(bool isAuthority, bool isMach { // Otherwise, allow encode with the private key. note that X509Certificate2.RawData will not provide the private key // you will have to re-export this cert if needed - outputCert = new X509Certificate2(container.Pfx, _password, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet); + if (CertificateHelper.CurrentOperatingSystem.IsMacOS()) + { + //string tempKeychainFilePath = Path.GetTempFileName(); + string tempKeychainFilePath = Path.Combine(Environment.CurrentDirectory, Path.GetRandomFileName()); + System.Security.Cryptography.X509Certificates.X509Store MacOsTempStore = CertificateHelper.GetMacOSX509Store(tempKeychainFilePath); + MacOsTempStore.Certificates.Import(container.Pfx, _password, X509KeyStorageFlags.Exportable); + MacOsTempStore.Close(); + MacOsTempStore.Dispose(); + + MacOsTempStore = CertificateHelper.GetMacOSX509Store(tempKeychainFilePath); + + outputCert = ((IEnumerable)MacOsTempStore.Certificates).FirstOrDefault(); + + if (outputCert == null) + { + Console.WriteLine("Couldn't find Certificate.."); + } + + MacOsTempStore.Dispose(); + if (File.Exists(tempKeychainFilePath)) + { + File.Delete(tempKeychainFilePath); + } + } + else + { + outputCert = new X509Certificate2(container.Pfx, _password, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet); + } } container.Subject = subject; diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.cs index c80d10bae19..9e2210bf86f 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.cs +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateGeneratorLibrary.cs @@ -23,9 +23,12 @@ public class CertificateGeneratorLibrary private static void RemoveCertificatesFromStore(StoreName storeName, StoreLocation storeLocation) { X509Store store = CertificateHelper.GetX509Store(storeName, storeLocation); - Console.WriteLine(" Checking StoreName '{0}'", storeName); + Console.WriteLine(" Checking StoreName '{0}', StoreLocation '{1}'", storeName, store.Location); { - store.Open(OpenFlags.ReadWrite | OpenFlags.IncludeArchived); + if (!CertificateHelper.CurrentOperatingSystem.IsMacOS()) + { + store.Open(OpenFlags.ReadWrite | OpenFlags.IncludeArchived); + } foreach (var cert in store.Certificates.Find(X509FindType.FindByIssuerName, CertificateIssuer, false)) { diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs index 62549f50b25..81aa53ba69d 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs @@ -52,7 +52,7 @@ public static X509Store GetX509Store(StoreName storeName, StoreLocation storeLoc else if (CurrentOperatingSystem.IsMacOS()) { // MacOS SafeKeychainHandle - GetMacOSX509Store(); + store = GetMacOSX509Store(); } return store; } @@ -62,16 +62,21 @@ public static X509Store GetX509Store(StoreName storeName, StoreLocation storeLoc internal static string OSXCustomKeychainPassword => "WCFKeychainFilePassword"; [MethodImpl(MethodImplOptions.NoInlining)] - public static X509Store GetMacOSX509Store() + public static X509Store GetMacOSX509Store(string storeFilePath = null) { + if (storeFilePath == null) + { + storeFilePath = OSXCustomKeychainFilePath; + } + SafeKeychainHandle keychain; - if (!File.Exists(OSXCustomKeychainFilePath)) + if (!File.Exists(storeFilePath)) { - keychain = SafeKeychainHandle.Create(OSXCustomKeychainFilePath, OSXCustomKeychainPassword); + keychain = SafeKeychainHandle.Create(storeFilePath, OSXCustomKeychainPassword); } else { - keychain = SafeKeychainHandle.Open(OSXCustomKeychainFilePath, OSXCustomKeychainPassword); + keychain = SafeKeychainHandle.Open(storeFilePath, OSXCustomKeychainPassword); } if (keychain.IsInvalid) diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateManager.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateManager.cs index 6edd5e3dacf..e3fc2c15089 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateManager.cs +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateManager.cs @@ -49,9 +49,12 @@ public static bool AddToStoreIfNeeded(StoreName storeName, StoreLocation storeLo try { store = CertificateHelper.GetX509Store(storeName, storeLocation); - + // We assume Bridge is running elevated - store.Open(OpenFlags.ReadWrite); + if (!CertificateHelper.CurrentOperatingSystem.IsMacOS()) + { + store.Open(OpenFlags.ReadWrite); + } existingCert = CertificateFromThumbprint(store, certificate.Thumbprint); if (existingCert == null) { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs index d3a8b2e92fe..0d2650da58d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs @@ -214,7 +214,10 @@ public static X509Certificate2 CertificateFromSubject(StoreName name, StoreLocat try { store = CertificateHelper.GetX509Store(name, location); - store.Open(OpenFlags.ReadOnly); + if (!store.IsOpen) + { + store.Open(OpenFlags.ReadOnly); + } X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindBySubjectName, subjectName, validOnly: true); return foundCertificates.Count == 0 ? null : foundCertificates[0]; } @@ -234,7 +237,10 @@ public static X509Certificate2 CertificateFromFriendlyName(StoreName name, Store try { store = CertificateHelper.GetX509Store(name, location); - store.Open(OpenFlags.ReadOnly); + if (!store.IsOpen) + { + store.Open(OpenFlags.ReadOnly); + } X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindByIssuerName, "DO_NOT_TRUST_WcfBridgeRootCA", false); string friendlyNameHash = CertificateGenerator.HashFriendlyNameToString(friendlyName); From bae0e73654ed30b96850a626d549ba16356bac26 Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Wed, 4 Sep 2024 20:54:12 +0300 Subject: [PATCH 03/12] update service code --- .../App_code/CoreWCF/NetHttpsBinding.cs | 45 +++++++++++++++++++ .../TcpDefaultResourceTestServiceHost.cs | 6 ++- .../testhosts/TcpNoSecurityTestServiceHost.cs | 6 ++- .../testhosts/TestHostWebServiceHost.cs | 6 +-- .../SelfHostedCoreWCFService.csproj | 45 +++++-------------- 5 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs new file mode 100644 index 00000000000..567efb8ab0c --- /dev/null +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#if NET + +using CoreWCF; +using CoreWCF.Channels; + +namespace WcfService +{ + //public enum BasicHttpsSecurityMode + //{ + // // + // // Summary: + // // The Transport security mode. + // Transport, + // // + // // Summary: + // // The TransportWithMessageCredential security mode. + // TransportWithMessageCredential + //} + + // Cast BasicHttpsSecurityMode (WCF) to BasicHttpSecurityMode (CoreWCF) + //internal enum BasicHttpsSecurityMode + //{ + // None, + // Transport, + // Message, + // TransportWithMessageCredential, + // TransportCredentialOnly + //} + + internal class NetHttpsBinding : NetHttpBinding + { + public NetHttpsBinding() : base((BasicHttpSecurityMode)BasicHttpsSecurityMode.Transport) + { + } + + public NetHttpsBinding(BasicHttpsSecurityMode securityMode) : base((BasicHttpSecurityMode)securityMode) + { + } + } +} +#endif diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpDefaultResourceTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpDefaultResourceTestServiceHost.cs index f1d8a29fb9b..4584407bfe7 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpDefaultResourceTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpDefaultResourceTestServiceHost.cs @@ -22,11 +22,13 @@ protected override IList GetBindings() { var bindings = new List(); bindings.Add(GetNetTcpBinding()); + +#if !NET if (!HostingEnvironment.IsHosted) { bindings.Add(GetNetNamedPipeBinding()); } - +#endif return bindings; } @@ -35,10 +37,12 @@ private Binding GetNetTcpBinding() return new NetTcpBinding() { Name = "tcp-default" }; } +#if !NET private Binding GetNetNamedPipeBinding() { return new NetNamedPipeBinding() { Name = "namedpipe-default" }; } +#endif public TcpDefaultResourceTestServiceHost(params Uri[] baseAddresses) : base(typeof(WcfService), baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpNoSecurityTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpNoSecurityTestServiceHost.cs index 25c7860a45d..c6e2efaeb20 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpNoSecurityTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpNoSecurityTestServiceHost.cs @@ -22,11 +22,13 @@ protected override IList GetBindings() { var bindings = new List(); bindings.Add(GetNetTcpBinding()); + +#if !NET if (!HostingEnvironment.IsHosted) { bindings.Add(GetNetNamedPipeBinding()); } - +#endif return bindings; } @@ -35,10 +37,12 @@ private Binding GetNetTcpBinding() return new NetTcpBinding(SecurityMode.None) { Name = "tcp-nosecurity" }; } +#if !NET private Binding GetNetNamedPipeBinding() { return new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { Name = "namedpipe-nosecurity" }; } +#endif public TcpNoSecurityTestServiceHost(params Uri[] baseAddresses) : base(typeof(WcfService), baseAddresses) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestHostWebServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestHostWebServiceHost.cs index 585faba21e2..d4144a710e9 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestHostWebServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestHostWebServiceHost.cs @@ -2,14 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#if NET -using CoreWCF; -#else +#if !NET using System; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; -#endif namespace WcfService { @@ -31,3 +28,4 @@ public TestHostWebServiceHost(Type serviceType, params Uri[] baseAddresses) } } } +#endif diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj index 422f7a554ed..4444e1c34c2 100644 --- a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj @@ -5,17 +5,17 @@ false false - + - - - - - + + + + + @@ -24,52 +24,29 @@ - - - - - - - - - - - - + + - - - - - - + - - - - - - - - + + - - From 274dc78e5ede3cf02e4b475321e8f2c62a381ef0 Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Thu, 12 Sep 2024 23:12:41 +0300 Subject: [PATCH 04/12] update arcade yml file --- System.ServiceModel.sln | 6 ------ azure-pipelines-arcade.yml | 6 ++---- .../SelfHostedCoreWCFService.csproj | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/System.ServiceModel.sln b/System.ServiceModel.sln index f2e998c82cf..6f61be3e376 100644 --- a/System.ServiceModel.sln +++ b/System.ServiceModel.sln @@ -89,8 +89,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binding.UDS.IntegrationTest EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.NetNamedPipe.Tests", "src\System.ServiceModel.NetNamedPipe\tests\System.ServiceModel.NetNamedPipe.Tests.csproj", "{FD188537-21AF-48C5-84FF-F8758F4C42A8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SelfHostedCoreWCFService", "src\System.Private.ServiceModel\tools\SelfHostedCoreWcfService\SelfHostedCoreWCFService.csproj", "{D89D949F-254B-4A29-AE78-DEB081ACA601}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -261,10 +259,6 @@ Global {FD188537-21AF-48C5-84FF-F8758F4C42A8}.Debug|Any CPU.Build.0 = Debug|Any CPU {FD188537-21AF-48C5-84FF-F8758F4C42A8}.Release|Any CPU.ActiveCfg = Release|Any CPU {FD188537-21AF-48C5-84FF-F8758F4C42A8}.Release|Any CPU.Build.0 = Release|Any CPU - {D89D949F-254B-4A29-AE78-DEB081ACA601}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D89D949F-254B-4A29-AE78-DEB081ACA601}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D89D949F-254B-4A29-AE78-DEB081ACA601}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D89D949F-254B-4A29-AE78-DEB081ACA601}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/azure-pipelines-arcade.yml b/azure-pipelines-arcade.yml index 93608eb37b4..ce165352f8c 100644 --- a/azure-pipelines-arcade.yml +++ b/azure-pipelines-arcade.yml @@ -24,8 +24,6 @@ variables: value: false - name: _RunAsInternal value: true -- name: _RunWithCoreWcfService - value: false - group: DotNet-Wcf-SDLValidation-Params resources: repositories: @@ -97,7 +95,7 @@ extends: clean: true - script: eng\common\cibuild.cmd -configuration $(_BuildConfig) -preparemachine $(_InternalBuildArgs) $(_TestArgs) /p:Test=false displayName: Windows Build / Publish - - powershell: eng\common\build.ps1 -configuration $(_BuildConfig) -preparemachine -ci -test -integrationTest -projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=Windows /p:RunWithCoreWcfService=$(_RunWithCoreWcfService) /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog + - powershell: eng\common\build.ps1 -configuration $(_BuildConfig) -preparemachine -ci -test -integrationTest -projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=Windows /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog displayName: Windows - Run Helix Tests env: SYSTEM_ACCESSTOKEN: $(System.AccessToken) @@ -116,4 +114,4 @@ extends: enableSourceLinkValidation: false SDLValidationParameters: enable: true - params: ' -SourceToolsList @("policheck","credscan") -TsaInstanceURL $(_TsaInstanceURL) -TsaProjectName $(_TsaProjectName) -TsaNotificationEmail $(_TsaNotificationEmail) -TsaCodebaseAdmin $(_TsaCodebaseAdmin) -TsaBugAreaPath $(_TsaBugAreaPath) -TsaIterationPath $(_TsaIterationPath) -TsaRepositoryName "WCF" -TsaCodebaseName "WCF" -TsaPublish $True' + params: ' -SourceToolsList @("policheck","credscan") -TsaInstanceURL $(_TsaInstanceURL) -TsaProjectName $(_TsaProjectName) -TsaNotificationEmail $(_TsaNotificationEmail) -TsaCodebaseAdmin $(_TsaCodebaseAdmin) -TsaBugAreaPath $(_TsaBugAreaPath) -TsaIterationPath $(_TsaIterationPath) -TsaRepositoryName "WCF" -TsaCodebaseName "WCF" -TsaPublish $True' \ No newline at end of file diff --git a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj index 4444e1c34c2..9b262c2562e 100644 --- a/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj +++ b/src/System.Private.ServiceModel/tools/SelfHostedCoreWcfService/SelfHostedCoreWCFService.csproj @@ -5,7 +5,7 @@ false false - + From 0f85880bcd00a1943460773e9e4ae5359f8a651d Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Mon, 14 Oct 2024 10:36:14 +0300 Subject: [PATCH 05/12] update dotnet version --- NuGet.config | 2 -- eng/SendToHelix.proj | 2 +- .../CertificateGeneratorLibrary/CertificateHelper.cs | 3 +-- .../IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs | 1 - .../IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs | 1 - 5 files changed, 2 insertions(+), 7 deletions(-) diff --git a/NuGet.config b/NuGet.config index b72212fed1b..89b7dfff87d 100644 --- a/NuGet.config +++ b/NuGet.config @@ -5,8 +5,6 @@ - - diff --git a/eng/SendToHelix.proj b/eng/SendToHelix.proj index a2ab9ba081f..de289642f84 100644 --- a/eng/SendToHelix.proj +++ b/eng/SendToHelix.proj @@ -19,7 +19,7 @@ - + aspnetcore-runtime Current diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs index 81aa53ba69d..f86f704a205 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs @@ -33,8 +33,7 @@ public static class CurrentOperatingSystem /// Returns true if current OS matches OSPlatform /// /// OS Platform to check for - public static bool IsOSPlatform(OSPlatform osPlatform) => - RuntimeInformation.IsOSPlatform(osPlatform); + public static bool IsOSPlatform(OSPlatform osPlatform) => RuntimeInformation.IsOSPlatform(osPlatform); } public static X509Store GetX509Store(StoreName storeName, StoreLocation storeLocation) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs index 518a27ca6ae..9863095aa04 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/BasicHttpsBinding.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. #if NET - using CoreWCF; using CoreWCF.Channels; diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs index 567efb8ab0c..a4b26e52469 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/NetHttpsBinding.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. #if NET - using CoreWCF; using CoreWCF.Channels; From d1ec63fffe8c310cb27ef4e74c40705e57748243 Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Wed, 20 Nov 2024 15:47:23 +0200 Subject: [PATCH 06/12] update --- eng/SendToHelix.proj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eng/SendToHelix.proj b/eng/SendToHelix.proj index de289642f84..236226a626e 100644 --- a/eng/SendToHelix.proj +++ b/eng/SendToHelix.proj @@ -86,6 +86,8 @@ $(HelixPreCommands);set DOTNET_CLI_HOME=%HELIX_WORKITEM_ROOT%\.dotnet $(HelixPreCommands);set NUGET_PACKAGES=%HELIX_WORKITEM_ROOT%\.nuget $(HelixPreCommands);set ServiceUri=localhost + $(HelixPreCommands);dir C:\ /s /b /o:gn | find "SelfHostedCoreWCFService" + $(HelixPreCommands);dir D:\ /s /b /o:gn | find "SelfHostedCoreWCFService" $(HelixPreCommands);%HELIX_CORRELATION_PAYLOAD%\SelfHostedCoreWCFService\$(Configuration)\net8.0\SelfHostedCoreWCFService bootstrap:true @@ -99,7 +101,7 @@ - + @@ -108,7 +110,7 @@ %(Identity) - + SelfHostedCoreWCFService From 41f3ec1683585c4efdeec9b19789b0c9b56c45af Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Thu, 5 Dec 2024 22:06:47 +0200 Subject: [PATCH 07/12] update service --- NuGet.config | 1 + eng/SendToHelix.proj | 28 +++++++++--------- .../App_code/CoreWCF/ServiceHostHelper.cs | 6 ++-- .../App_code/TestDefinitionHelper.cs | 29 ++++++++++--------- .../HttpsClientCertificateTestServiceHost.cs | 1 + .../testhosts/WebSocketTestServiceHosts.cs | 4 ++- .../SelfHostedCoreWCFService.csproj | 2 -- 7 files changed, 37 insertions(+), 34 deletions(-) diff --git a/NuGet.config b/NuGet.config index 66f1d7263bc..1311ab2da13 100644 --- a/NuGet.config +++ b/NuGet.config @@ -4,6 +4,7 @@ + diff --git a/eng/SendToHelix.proj b/eng/SendToHelix.proj index 236226a626e..8025dd6dad2 100644 --- a/eng/SendToHelix.proj +++ b/eng/SendToHelix.proj @@ -1,4 +1,4 @@ - + pr/dotnet/wcf/$(BUILD_SOURCEBRANCH)/ official/dotnet/wcf/$(BUILD_SOURCEBRANCH)/ @@ -26,10 +26,10 @@ - - - - + + + + $(XUnitPublishTargetFramework) @@ -74,24 +74,26 @@ false + + $(HelixPreCommands);export _TestJob=$(TestJob);export _RunWithCoreWCFService=$(RunWithCoreWCFService) + + $(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);set PATH=%HELIX_CORRELATION_PAYLOAD%\dotnet-cli%3B%PATH% $(HelixPreCommands);set DOTNET_ROOT=%HELIX_CORRELATION_PAYLOAD%\dotnet-cli;set DOTNET_CLI_TELEMETRY_OPTOUT=1 $(HelixPreCommands);set DOTNET_CLI_HOME=%HELIX_WORKITEM_ROOT%\.dotnet $(HelixPreCommands);set NUGET_PACKAGES=%HELIX_WORKITEM_ROOT%\.nuget $(HelixPreCommands);set ServiceUri=localhost - $(HelixPreCommands);dir C:\ /s /b /o:gn | find "SelfHostedCoreWCFService" - $(HelixPreCommands);dir D:\ /s /b /o:gn | find "SelfHostedCoreWCFService" $(HelixPreCommands);%HELIX_CORRELATION_PAYLOAD%\SelfHostedCoreWCFService\$(Configuration)\net8.0\SelfHostedCoreWCFService bootstrap:true - + $(HelixPreCommands);export PATH=$HELIX_CORRELATION_PAYLOAD/dotnet-cli:$PATH $(HelixPreCommands);export DOTNET_ROOT=$HELIX_CORRELATION_PAYLOAD/dotnet-cli;export DOTNET_CLI_TELEMETRY_OPTOUT=1 $(HelixPreCommands);export DOTNET_CLI_HOME=$HELIX_WORKITEM_ROOT/.dotnet @@ -100,17 +102,13 @@ $(HelixPreCommands);dotnet exec --roll-forward Major $HELIX_CORRELATION_PAYLOAD/SelfHostedCoreWCFService/$(Configuration)/net8.0/SelfHostedCoreWCFService.dll bootstrap:true - - - - %(Identity) - - + + SelfHostedCoreWCFService diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/ServiceHostHelper.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/ServiceHostHelper.cs index f0dfdd0af20..dbf842f7d35 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/ServiceHostHelper.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CoreWCF/ServiceHostHelper.cs @@ -77,10 +77,10 @@ public static async Task ServiceBootstrap() Environment.Exit(1); } - public static Enum ToServiceSchema(string CoreWcfScheme) => CoreWcfScheme switch + public static Enum ToServiceSchema(string CoreWcfScheme, bool usesWebsockets) => CoreWcfScheme switch { - "http" => ServiceSchema.HTTP, - "https" => ServiceSchema.HTTPS, + "http" => usesWebsockets ? ServiceSchema.WS : ServiceSchema.HTTP, + "https" => usesWebsockets ? ServiceSchema.WSS : ServiceSchema.HTTPS, "net.tcp" => ServiceSchema.NETTCP, "net.pipe" => ServiceSchema.NETPIPE, "ws" => ServiceSchema.WS, 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 e946eddeabb..fa366afb501 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestDefinitionHelper.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestDefinitionHelper.cs @@ -7,6 +7,7 @@ using System.Net; using System.Security.Claims; using System.Security.Cryptography.X509Certificates; +using CoreWCF.Channels; using CoreWCF.Configuration; using CoreWCF.Description; using idunno.Authentication.Basic; @@ -41,17 +42,11 @@ internal static IDictionary BaseAddresses dict[ServiceSchema.HTTPS] = string.Format(@"https://localhost:{0}", httpsPort); var tcpPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("tcpPort")) ? DefaultTcpPort : int.Parse(Environment.GetEnvironmentVariable("tcpPort")); dict[ServiceSchema.NETTCP] = string.Format(@"net.tcp://localhost:{0}", tcpPort); -#if NET - var websocketPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketPort")) ? DefaultWebSocketPort : int.Parse(Environment.GetEnvironmentVariable("websocketPort")); - dict[ServiceSchema.WS] = string.Format(@"ws://localhost:{0}", websocketPort); - var websocketsPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketsPort")) ? DefaultWebSocketSPort : int.Parse(Environment.GetEnvironmentVariable("websocketsPort")); - dict[ServiceSchema.WSS] = string.Format(@"wss://localhost:{0}", websocketsPort); -#else var websocketPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketPort")) ? DefaultWebSocketPort : int.Parse(Environment.GetEnvironmentVariable("websocketPort")); dict[ServiceSchema.WS] = string.Format(@"http://localhost:{0}", websocketPort); var websocketsPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketsPort")) ? DefaultWebSocketSPort : int.Parse(Environment.GetEnvironmentVariable("websocketsPort")); dict[ServiceSchema.WSS] = string.Format(@"https://localhost:{0}", websocketsPort); -#endif + s_baseAddresses = dict; dict[ServiceSchema.NETPIPE] = @"net.pipe://localhost"; Console.WriteLine("Using base addresses:"); @@ -149,7 +144,7 @@ internal static async Task StartHosts() .Configure(app => { app.UseAuthentication(); - app.UseAuthorization(); + app.UseAuthorization(); app.UseServiceModel(serviceBuilder => { foreach (var serviceTestHost in GetAttributedServiceHostTypes()) @@ -194,18 +189,26 @@ internal static async Task StartHosts() var serviceHost = (ServiceHost)Activator.CreateInstance(serviceTestHost, serviceTestHostOptionsDict[serviceHostTypeName].serviceBaseAddresses.ToArray()); serviceBuilder.AddService(serviceHost.ServiceType, options => { - var localHostTypeName = serviceHostTypeName; options.BaseAddresses.Clear(); - foreach (var baseAddress in BaseAddresses.Values) + foreach (var baseAddress in BaseAddresses) { - //if (!options.BaseAddresses.Contains(baseAddress)) - options.BaseAddresses.Add(new Uri(baseAddress)); + if ((BaseAddresses.ContainsKey(ServiceSchema.HTTP) && baseAddress.Key == ServiceSchema.WS) || + (BaseAddresses.ContainsKey(ServiceSchema.HTTPS) && baseAddress.Key == ServiceSchema.WSS)) + { + continue; + } + + options.BaseAddresses.Add(new Uri(baseAddress.Value)); } }); foreach (var endpoint in serviceHost.Endpoints) { - Enum schema = ServiceHostHelper.ToServiceSchema(endpoint.Binding.Scheme); + var customBinding = new CustomBinding(endpoint.Binding); + var htbe = customBinding.Elements.Find(); + bool usesWebsockets = htbe != null && htbe.WebSocketSettings.TransportUsage == WebSocketTransportUsage.Always; + + Enum schema = ServiceHostHelper.ToServiceSchema(endpoint.Binding.Scheme, usesWebsockets); string basePath = serviceTestHostOptionsDict[serviceHostTypeName].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); diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsClientCertificateTestServiceHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsClientCertificateTestServiceHost.cs index df7aa1003d6..3b89c2caa60 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsClientCertificateTestServiceHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/HttpsClientCertificateTestServiceHost.cs @@ -17,6 +17,7 @@ namespace WcfService { [TestServiceDefinition(Schema = ServiceSchema.HTTPS, BasePath = "ClientCertificateAccepted/HttpsClientCertificate.svc")] + [TestServiceDefinition(Schema = ServiceSchema.WSS, BasePath = "ClientCertificateAccepted/HttpsClientCertificate.svc")] public class HttpsClientCertificateTestServiceHost : TestServiceHostBase { protected override IList GetBindings() diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WebSocketTestServiceHosts.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WebSocketTestServiceHosts.cs index 9cf89ff9158..cddb4787c87 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WebSocketTestServiceHosts.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/WebSocketTestServiceHosts.cs @@ -21,7 +21,9 @@ public class DuplexWebSocketTestServiceHost : TestServiceHostBase - @@ -46,7 +45,6 @@ - From 95a8cdfc302f2caea5136c23a9ebfef773b2e31b Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Fri, 20 Dec 2024 20:54:26 +0200 Subject: [PATCH 08/12] update code --- .../App_code/testhosts/DuplexTestServiceHosts.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs index e6cfca90fce..38bc6d529f9 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs @@ -166,7 +166,7 @@ public class DuplexCallbackErrorHandlerServiceHost : TestServiceHostBase Date: Fri, 10 Jan 2025 06:41:21 +0200 Subject: [PATCH 09/12] update yml file --- azure-pipelines-arcade-PR.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines-arcade-PR.yml b/azure-pipelines-arcade-PR.yml index 75d0f693d55..f4b1ae96d01 100644 --- a/azure-pipelines-arcade-PR.yml +++ b/azure-pipelines-arcade-PR.yml @@ -200,7 +200,7 @@ stages: --projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=Linux - /p:RunWithCoreWcfService=$($Env:_RunWithCoreWcfService) + /p:RunWithCoreWcfService=$(variables._RunWithCoreWcfService) /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog displayName: Linux - Run Helix Tests env: From 994f24f5e6155ae862702160b961f6faa1f6dfd1 Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Sat, 11 Jan 2025 04:38:26 +0200 Subject: [PATCH 10/12] update --- NuGet.config | 1 - azure-pipelines-arcade-PR.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 1311ab2da13..66f1d7263bc 100644 --- a/NuGet.config +++ b/NuGet.config @@ -4,7 +4,6 @@ - diff --git a/azure-pipelines-arcade-PR.yml b/azure-pipelines-arcade-PR.yml index f4b1ae96d01..20fcbe4bc3e 100644 --- a/azure-pipelines-arcade-PR.yml +++ b/azure-pipelines-arcade-PR.yml @@ -200,7 +200,6 @@ stages: --projects $(Build.SourcesDirectory)/eng/SendToHelix.proj $(_TestArgs) /p:TestJob=Linux - /p:RunWithCoreWcfService=$(variables._RunWithCoreWcfService) /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog displayName: Linux - Run Helix Tests env: @@ -208,6 +207,7 @@ stages: ServiceHost: $(_serviceUri) RunAsPublic: $(_RunAsPublic) RunAsInternal: $(_RunAsInternal) + RunWithCoreWcfService: $(_RunWithCoreWcfService) IsWindowsBuild: false # Only build and test MacOS in PR and CI builds. From 8ef3dce90c74a8b1bb3e015e3f3590ffbd61626d Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Sat, 11 Jan 2025 07:34:33 +0200 Subject: [PATCH 11/12] update --- eng/SendToHelix.proj | 4 ---- .../App_code/testhosts/DuplexTestServiceHosts.cs | 9 +++------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/eng/SendToHelix.proj b/eng/SendToHelix.proj index 8025dd6dad2..9ec34cc7e7f 100644 --- a/eng/SendToHelix.proj +++ b/eng/SendToHelix.proj @@ -73,10 +73,6 @@ false - - - $(HelixPreCommands);export _TestJob=$(TestJob);export _RunWithCoreWCFService=$(RunWithCoreWCFService) - $(HelixPreCommands);chmod a+x $HELIX_CORRELATION_PAYLOAD/InstallRootCertificate.sh diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs index 38bc6d529f9..26cdfcae321 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/DuplexTestServiceHosts.cs @@ -112,13 +112,10 @@ protected override void ApplyConfiguration() { base.ApplyConfiguration(); // Ensure the https certificate is installed before this endpoint resource is used - string thumbprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager").Thumbprint; - + X509Certificate2 cert = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - Machine certificate generated by the CertificateManager"); + this.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; - this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, - StoreName.My, - X509FindType.FindByThumbprint, - thumbprint); + this.Credentials.ServiceCertificate.Certificate = cert; } public DuplexCallbackTcpCertificateCredentialTestServiceHost(params Uri[] baseAddresses) From c39431e7b26911bcca673462029cea1d67ef30a6 Mon Sep 17 00:00:00 2001 From: Ahmed Afifi Date: Tue, 21 Jan 2025 10:40:56 +0200 Subject: [PATCH 12/12] update certificate helper --- .../CertificateHelper.cs | 15 +++++++++++++++ .../IISHostedWcfService/App_code/TestHost.cs | 9 +-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs index f86f704a205..98df9654241 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGeneratorLibrary/CertificateHelper.cs @@ -53,9 +53,24 @@ public static X509Store GetX509Store(StoreName storeName, StoreLocation storeLoc // MacOS SafeKeychainHandle store = GetMacOSX509Store(); } + + store = EnsureStoreIsOpened(store); return store; } + private static X509Store EnsureStoreIsOpened(X509Store store) + { + try + { + // Try opening the store in read-only mode + store.Open(OpenFlags.ReadOnly); + } + catch { } + + return store; + } + + internal static string OSXCustomKeychainFilePath => Path.Combine(Environment.CurrentDirectory, "wcfLocal.keychain"); internal static string OSXCustomKeychainPassword => "WCFKeychainFilePassword"; diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs index 0d2650da58d..1673d0bf76d 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/TestHost.cs @@ -214,10 +214,7 @@ public static X509Certificate2 CertificateFromSubject(StoreName name, StoreLocat try { store = CertificateHelper.GetX509Store(name, location); - if (!store.IsOpen) - { - store.Open(OpenFlags.ReadOnly); - } + X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindBySubjectName, subjectName, validOnly: true); return foundCertificates.Count == 0 ? null : foundCertificates[0]; } @@ -237,10 +234,6 @@ public static X509Certificate2 CertificateFromFriendlyName(StoreName name, Store try { store = CertificateHelper.GetX509Store(name, location); - if (!store.IsOpen) - { - store.Open(OpenFlags.ReadOnly); - } X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindByIssuerName, "DO_NOT_TRUST_WcfBridgeRootCA", false); string friendlyNameHash = CertificateGenerator.HashFriendlyNameToString(friendlyName);