-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3ba5c9
commit 38d0eb1
Showing
17 changed files
with
503 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/System.Private.ServiceModel/tests/Scenarios/Binding/UDS/ServiceContract/EchoService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using CoreWCF; | ||
|
||
namespace Binding.UDS.IntegrationTests.ServiceContract | ||
{ | ||
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)] | ||
public class EchoService : IEchoService | ||
{ | ||
public string Echo(string echo) | ||
{ | ||
return echo; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/System.Private.ServiceModel/tests/Scenarios/Binding/UDS/ServiceContract/IEchoService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.ServiceModel; | ||
|
||
namespace Binding.UDS.IntegrationTests.ServiceContract | ||
{ | ||
internal static partial class Constants | ||
{ | ||
public const string NS = "http://tempuri.org/"; | ||
public const string TESTSERVICE_NAME = nameof(IEchoService); | ||
public const string OPERATION_BASE = NS + TESTSERVICE_NAME + "/"; | ||
} | ||
|
||
[ServiceContract(Namespace = Constants.NS, Name = Constants.TESTSERVICE_NAME)] | ||
public interface IEchoService | ||
{ | ||
[OperationContract(Name = "Echo", Action = Constants.OPERATION_BASE + "Echo", | ||
ReplyAction = Constants.OPERATION_BASE + "EchoResponse")] | ||
string Echo(string echo); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/System.Private.ServiceModel/tests/Scenarios/Binding/UDS/ServiceHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// 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.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Security.Cryptography.X509Certificates; | ||
using CoreWCF.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Binding.UDS.IntegrationTests | ||
{ | ||
internal class ServiceHelper | ||
{ | ||
public static IHost CreateWebHostBuilder<TStartup>(string linuxSocketFilepath = "", [CallerMemberName] string callerMethodName = "") where TStartup : class | ||
{ | ||
var startupType = typeof(TStartup); | ||
var configureServicesMethod = startupType.GetMethod("ConfigureServices", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[] { typeof(IServiceCollection) }); | ||
var configureMethod = startupType.GetMethod("Configure", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[] { typeof(IHost) }); | ||
var startupInstance = Activator.CreateInstance(startupType); | ||
var hostBuilder = Host.CreateDefaultBuilder(Array.Empty<string>()); | ||
hostBuilder.UseUnixDomainSocket(options => | ||
{ | ||
options.Listen(new Uri("net.uds://" + linuxSocketFilepath)); | ||
}); | ||
if (configureServicesMethod != null) | ||
{ | ||
var configureServiceAction = (Action<IServiceCollection>)configureServicesMethod.CreateDelegate(typeof(Action<IServiceCollection>), startupInstance); | ||
hostBuilder.ConfigureServices(configureServiceAction); | ||
} | ||
|
||
IHost host = hostBuilder.Build(); | ||
if (configureMethod != null) | ||
{ | ||
var configureAction = (Action<IHost>)configureMethod.CreateDelegate(typeof(Action<IHost>), startupInstance); | ||
configureAction(host); | ||
} | ||
|
||
return host; | ||
} | ||
|
||
|
||
//only for test, don't use in production code | ||
public static X509Certificate2 GetServiceCertificate() | ||
{ | ||
string AspNetHttpsOid = "1.3.6.1.4.1.311.84.1.1"; | ||
X509Certificate2 foundCert = null; | ||
using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser)) | ||
{ | ||
// X509Store.Certificates creates a new instance of X509Certificate2Collection with | ||
// each access to the property. The collection needs to be cleaned up correctly so | ||
// keeping a single reference to fetched collection. | ||
store.Open(OpenFlags.ReadOnly); | ||
var certificates = store.Certificates; | ||
foreach (var cert in certificates) | ||
{ | ||
foreach (var extension in cert.Extensions) | ||
{ | ||
if (AspNetHttpsOid.Equals(extension.Oid?.Value)) | ||
{ | ||
// Always clone certificate instances when you don't own the creation | ||
foundCert = new X509Certificate2(cert); | ||
break; | ||
} | ||
} | ||
|
||
if (foundCert != null) | ||
{ | ||
break; | ||
} | ||
} | ||
// Cleanup | ||
foreach (var cert in certificates) | ||
{ | ||
cert.Dispose(); | ||
} | ||
} | ||
|
||
return foundCert; | ||
} | ||
|
||
public static void CloseServiceModelObjects(params System.ServiceModel.ICommunicationObject[] objects) | ||
{ | ||
foreach (System.ServiceModel.ICommunicationObject comObj in objects) | ||
{ | ||
try | ||
{ | ||
if (comObj == null) | ||
{ | ||
continue; | ||
} | ||
// Only want to call Close if it is in the Opened state | ||
if (comObj.State == System.ServiceModel.CommunicationState.Opened) | ||
{ | ||
comObj.Close(); | ||
} | ||
// Anything not closed by this point should be aborted | ||
if (comObj.State != System.ServiceModel.CommunicationState.Closed) | ||
{ | ||
comObj.Abort(); | ||
} | ||
} | ||
catch (TimeoutException) | ||
{ | ||
comObj.Abort(); | ||
} | ||
catch (System.ServiceModel.CommunicationException) | ||
{ | ||
comObj.Abort(); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.