-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
44 changed files
with
2,111 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net48</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="EMG.Utilities.ServiceModel" Version="1.8.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,57 @@ | ||
using System; | ||
using System.ServiceModel; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EMG.Utilities.ServiceModel; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using EndpointAddress = EMG.Utilities.ServiceModel.Configuration.EndpointAddress; | ||
|
||
namespace DiscoverableService | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddLogging(); | ||
|
||
services.AddOptions(); | ||
|
||
services.AddWcfService<MyTestService>(service => | ||
{ | ||
service.AddNetTcpEndpoint(typeof(IMyService), EndpointAddress.ForNetTcp(11000), binding => binding.WithNoSecurity()).Discoverable(); | ||
}); | ||
|
||
services.AddDiscovery<NetTcpBinding>(new Uri("net.tcp://localhost:8001/Announcement"), TimeSpan.FromSeconds(10), b => b.WithNoSecurity()); | ||
|
||
var sp = services.BuildServiceProvider(); | ||
|
||
var hostedService = sp.GetRequiredService<IHostedService>(); | ||
|
||
await hostedService.StartAsync(CancellationToken.None); | ||
|
||
Console.WriteLine("Service started!"); | ||
|
||
Console.ReadLine(); | ||
|
||
await hostedService.StopAsync(CancellationToken.None); | ||
} | ||
} | ||
|
||
[ServiceContract(Namespace = "http://samples.educations.com/", Name = "MyService")] | ||
public interface IMyService | ||
{ | ||
[OperationContract] | ||
string Echo(string message); | ||
} | ||
|
||
public class MyTestService : IMyService | ||
{ | ||
public string Echo(string message) | ||
{ | ||
return message; | ||
} | ||
} | ||
} |
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net48</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\DependencyInjection\ServiceModel.Discovery\ServiceModel.Discovery.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.ServiceModel" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Channels; | ||
using EMG.Extensions.DependencyInjection.Discovery.BindingCustomizations; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Discovery | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
["Discovery:ProbeEndpoint"] = "net.tcp://localhost:8001/Probe" | ||
}; | ||
|
||
var configurationBuilder = new ConfigurationBuilder(); | ||
configurationBuilder.AddInMemoryCollection(settings); | ||
|
||
var configuration = configurationBuilder.Build(); | ||
|
||
var services = new ServiceCollection(); | ||
|
||
services.AddLogging(l => l.AddConsole()); | ||
|
||
services.AddServiceDiscovery() | ||
.ConfigureServiceDiscovery(configuration.GetSection("Discovery")) | ||
.ConfigureServiceDiscovery(o => o.DiscoveryBindingFactory = () => new NetTcpBinding(SecurityMode.None)); | ||
|
||
// Customizes the binding used for net.tcp endpoints for the IMyService service | ||
//services.AddServiceBindingCustomization<IMyService>(Uri.UriSchemeNetTcp, () => new NetTcpBinding(SecurityMode.None)); | ||
|
||
// Customizes the binding used for net.tcp endpoints for all services | ||
services.AddBindingCustomization<UnsafeNetTcpBindingFactoryCustomization>(); | ||
|
||
services.DiscoverService<IMyService>(); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var service = serviceProvider.GetService<IMyService>(); | ||
|
||
var isServiceFound = service != null; | ||
|
||
Console.WriteLine($"Service { (isServiceFound ? "" : "not ")}found"); | ||
|
||
if (isServiceFound) | ||
{ | ||
var response = service.Echo("This is my message"); | ||
|
||
Console.WriteLine(response); | ||
} | ||
} | ||
} | ||
|
||
[ServiceContract(Namespace="http://samples.educations.com/", Name="MyService")] | ||
public interface IMyService | ||
{ | ||
[OperationContract] | ||
string Echo(string message); | ||
} | ||
|
||
public class UnsafeNetTcpBindingFactoryCustomization : IBindingFactoryCustomization | ||
{ | ||
public Type ServiceType { get; } = null; | ||
|
||
public string UriScheme { get; } = Uri.UriSchemeNetTcp; | ||
|
||
public Binding Create() => new NetTcpBinding(SecurityMode.None); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
samples/DependencyInjection/DiscoveryAdapter/DiscoveryAdapter.csproj
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\DependencyInjection\ServiceModel.DiscoveryAdapter\ServiceModel.DiscoveryAdapter.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.