Skip to content

Commit 8f48213

Browse files
birojnayakmconnew
authored andcommitted
Unix domain socket binding on WCF Client
1 parent 7f245dc commit 8f48213

File tree

48 files changed

+5078
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5078
-2
lines changed

System.ServiceModel.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.NetTcp"
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.NetTcp.Tests", "src\System.ServiceModel.NetTcp\tests\System.ServiceModel.NetTcp.Tests.csproj", "{95C6CD71-6965-44E1-8F05-01F2F150B1E0}"
1919
EndProject
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.UnixDomainSocket.Tests", "src\System.ServiceModel.UnixDomainSocket\tests\System.ServiceModel.UnixDomainSocket.Tests.csproj", "{58918456-A2B2-431F-BB95-BAAD2818BFC7}"
21+
EndProject
2022
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binding.Custom.IntegrationTests", "src\System.Private.ServiceModel\tests\Scenarios\Binding\Custom\Binding.Custom.IntegrationTests.csproj", "{D878F354-E120-476A-A90A-9E601A7E7580}"
2123
EndProject
2224
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binding.Http.IntegrationTests", "src\System.Private.ServiceModel\tests\Scenarios\Binding\Http\Binding.Http.IntegrationTests.csproj", "{2789D52D-9C17-4FCE-B81C-41B65C3FAFF9}"
@@ -83,6 +85,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.NetFram
8385
EndProject
8486
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.NetNamedPipe", "src\System.ServiceModel.NetNamedPipe\src\System.ServiceModel.NetNamedPipe.csproj", "{5ECB8887-D7EE-449F-9439-35D0BBBB1E07}"
8587
EndProject
88+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.UnixDomainSocket", "src\System.ServiceModel.UnixDomainSocket\src\System.ServiceModel.UnixDomainSocket.csproj", "{1664DB18-8451-43C0-8A85-2DD9189C3897}"
89+
EndProject
90+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binding.UDS.IntegrationTests", "src\System.Private.ServiceModel\tests\Scenarios\Binding\UDS\Binding.UDS.IntegrationTests.csproj", "{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}"
91+
EndProject
8692
Global
8793
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8894
Debug|Any CPU = Debug|Any CPU
@@ -117,6 +123,10 @@ Global
117123
{95C6CD71-6965-44E1-8F05-01F2F150B1E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
118124
{95C6CD71-6965-44E1-8F05-01F2F150B1E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
119125
{95C6CD71-6965-44E1-8F05-01F2F150B1E0}.Release|Any CPU.Build.0 = Release|Any CPU
126+
{58918456-A2B2-431F-BB95-BAAD2818BFC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
127+
{58918456-A2B2-431F-BB95-BAAD2818BFC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
128+
{58918456-A2B2-431F-BB95-BAAD2818BFC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
129+
{58918456-A2B2-431F-BB95-BAAD2818BFC7}.Release|Any CPU.Build.0 = Release|Any CPU
120130
{D878F354-E120-476A-A90A-9E601A7E7580}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
121131
{D878F354-E120-476A-A90A-9E601A7E7580}.Debug|Any CPU.Build.0 = Debug|Any CPU
122132
{D878F354-E120-476A-A90A-9E601A7E7580}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -241,6 +251,14 @@ Global
241251
{5ECB8887-D7EE-449F-9439-35D0BBBB1E07}.Debug|Any CPU.Build.0 = Debug|Any CPU
242252
{5ECB8887-D7EE-449F-9439-35D0BBBB1E07}.Release|Any CPU.ActiveCfg = Release|Any CPU
243253
{5ECB8887-D7EE-449F-9439-35D0BBBB1E07}.Release|Any CPU.Build.0 = Release|Any CPU
254+
{1664DB18-8451-43C0-8A85-2DD9189C3897}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
255+
{1664DB18-8451-43C0-8A85-2DD9189C3897}.Debug|Any CPU.Build.0 = Debug|Any CPU
256+
{1664DB18-8451-43C0-8A85-2DD9189C3897}.Release|Any CPU.ActiveCfg = Release|Any CPU
257+
{1664DB18-8451-43C0-8A85-2DD9189C3897}.Release|Any CPU.Build.0 = Release|Any CPU
258+
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
259+
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}.Debug|Any CPU.Build.0 = Debug|Any CPU
260+
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}.Release|Any CPU.ActiveCfg = Release|Any CPU
261+
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}.Release|Any CPU.Build.0 = Release|Any CPU
244262
EndGlobalSection
245263
GlobalSection(SolutionProperties) = preSolution
246264
HideSolutionNode = FALSE
@@ -249,6 +267,7 @@ Global
249267
{10C03A32-1B1F-4EF8-8041-92C34DAD221E} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
250268
{7805E0FD-3320-432B-91E1-D7BB7ABB781E} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
251269
{95C6CD71-6965-44E1-8F05-01F2F150B1E0} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
270+
{58918456-A2B2-431F-BB95-BAAD2818BFC7} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
252271
{D878F354-E120-476A-A90A-9E601A7E7580} = {D6302510-AB10-4775-BCE9-98FA96FDEB76}
253272
{2789D52D-9C17-4FCE-B81C-41B65C3FAFF9} = {D6302510-AB10-4775-BCE9-98FA96FDEB76}
254273
{B38A2272-F260-4303-964C-ACDC9BADEB79} = {D6302510-AB10-4775-BCE9-98FA96FDEB76}
@@ -276,6 +295,7 @@ Global
276295
{A3F8C509-AAE7-4391-9272-2221055CC17E} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
277296
{E8E40B62-E737-4768-82C2-039E90ED9A39} = {D6302510-AB10-4775-BCE9-98FA96FDEB76}
278297
{88918456-A2B2-431F-BB95-BAAD2818BFC7} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
298+
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58} = {D6302510-AB10-4775-BCE9-98FA96FDEB76}
279299
EndGlobalSection
280300
GlobalSection(ExtensibilityGlobals) = postSolution
281301
SolutionGuid = {E0638FAC-BA6B-4E18-BAE6-468C3191BE58}

src/System.Private.ServiceModel/tests/Common/Infrastructure/ConditionalWcfTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public static bool Is_Windows()
9898
ConditionalTestDetectors.IsWindows);
9999
}
100100

101+
public static bool IsNotWindows()
102+
{
103+
return !Is_Windows();
104+
}
105+
101106
// Returns 'true' if both the server and the client are domain-joined.
102107
public static bool Domain_Joined()
103108
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>$(ScenarioTestTargetFrameworks)</TargetFrameworks>
4+
<CLSCompliant>false</CLSCompliant>
5+
<IsTestProject>true</IsTestProject>
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="CoreWCF.UnixDomainSocket" Version="1.5.0-preview1" />
11+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="$(WcfInfrastructureCommonProj)" />
16+
<ProjectReference Include="$(WcfScenarioTestCommonProj)" />
17+
<ProjectReference Include="..\..\..\..\..\System.ServiceModel.UnixDomainSocket\src\System.ServiceModel.UnixDomainSocket.csproj" />
18+
</ItemGroup>
19+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using CoreWCF;
5+
6+
namespace Binding.UDS.IntegrationTests.ServiceContract
7+
{
8+
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
9+
public class EchoService : IEchoService
10+
{
11+
public string Echo(string echo)
12+
{
13+
return echo;
14+
}
15+
}
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.ServiceModel;
5+
6+
namespace Binding.UDS.IntegrationTests.ServiceContract
7+
{
8+
internal static partial class Constants
9+
{
10+
public const string NS = "http://tempuri.org/";
11+
public const string TESTSERVICE_NAME = nameof(IEchoService);
12+
public const string OPERATION_BASE = NS + TESTSERVICE_NAME + "/";
13+
}
14+
15+
[ServiceContract(Namespace = Constants.NS, Name = Constants.TESTSERVICE_NAME)]
16+
public interface IEchoService
17+
{
18+
[OperationContract(Name = "Echo", Action = Constants.OPERATION_BASE + "Echo",
19+
ReplyAction = Constants.OPERATION_BASE + "EchoResponse")]
20+
string Echo(string echo);
21+
}
22+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Reflection;
6+
using System.Runtime.CompilerServices;
7+
using System.Security.Cryptography.X509Certificates;
8+
using System.Threading.Tasks;
9+
using CoreWCF.Configuration;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
12+
13+
namespace Binding.UDS.IntegrationTests
14+
{
15+
internal class ServiceHelper
16+
{
17+
public static IHost CreateWebHostBuilder<TStartup>(string linuxSocketFilepath = "", [CallerMemberName] string callerMethodName = "") where TStartup : class
18+
{
19+
var startupType = typeof(TStartup);
20+
var configureServicesMethod = startupType.GetMethod("ConfigureServices", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[] { typeof(IServiceCollection) });
21+
var configureMethod = startupType.GetMethod("Configure", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[] { typeof(IHost) });
22+
var startupInstance = Activator.CreateInstance(startupType);
23+
var hostBuilder = Host.CreateDefaultBuilder(Array.Empty<string>());
24+
hostBuilder.UseUnixDomainSocket(options =>
25+
{
26+
options.Listen(new Uri("net.uds://" + linuxSocketFilepath));
27+
});
28+
if (configureServicesMethod != null)
29+
{
30+
var configureServiceAction = (Action<IServiceCollection>)configureServicesMethod.CreateDelegate(typeof(Action<IServiceCollection>), startupInstance);
31+
hostBuilder.ConfigureServices(configureServiceAction);
32+
}
33+
34+
IHost host = hostBuilder.Build();
35+
if (configureMethod != null)
36+
{
37+
var configureAction = (Action<IHost>)configureMethod.CreateDelegate(typeof(Action<IHost>), startupInstance);
38+
configureAction(host);
39+
}
40+
41+
return host;
42+
}
43+
44+
45+
//only for test, don't use in production code
46+
public static X509Certificate2 GetServiceCertificate()
47+
{
48+
string AspNetHttpsOid = "1.3.6.1.4.1.311.84.1.1";
49+
X509Certificate2 foundCert = null;
50+
using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
51+
{
52+
// X509Store.Certificates creates a new instance of X509Certificate2Collection with
53+
// each access to the property. The collection needs to be cleaned up correctly so
54+
// keeping a single reference to fetched collection.
55+
store.Open(OpenFlags.ReadOnly);
56+
var certificates = store.Certificates;
57+
foreach (var cert in certificates)
58+
{
59+
foreach (var extension in cert.Extensions)
60+
{
61+
if (AspNetHttpsOid.Equals(extension.Oid?.Value))
62+
{
63+
// Always clone certificate instances when you don't own the creation
64+
foundCert = new X509Certificate2(cert);
65+
break;
66+
}
67+
}
68+
69+
if (foundCert != null)
70+
{
71+
break;
72+
}
73+
}
74+
// Cleanup
75+
foreach (var cert in certificates)
76+
{
77+
cert.Dispose();
78+
}
79+
}
80+
81+
if (foundCert == null)
82+
{
83+
foundCert = ServiceUtilHelper.ClientCertificate;
84+
}
85+
86+
return foundCert;
87+
}
88+
89+
public static void CloseServiceModelObjects(params System.ServiceModel.ICommunicationObject[] objects)
90+
{
91+
foreach (System.ServiceModel.ICommunicationObject comObj in objects)
92+
{
93+
try
94+
{
95+
if (comObj == null)
96+
{
97+
continue;
98+
}
99+
// Only want to call Close if it is in the Opened state
100+
if (comObj.State == System.ServiceModel.CommunicationState.Opened)
101+
{
102+
comObj.Close();
103+
}
104+
// Anything not closed by this point should be aborted
105+
if (comObj.State != System.ServiceModel.CommunicationState.Closed)
106+
{
107+
comObj.Abort();
108+
}
109+
}
110+
catch (TimeoutException)
111+
{
112+
comObj.Abort();
113+
}
114+
catch (System.ServiceModel.CommunicationException)
115+
{
116+
comObj.Abort();
117+
}
118+
}
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)