-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration with Microsoft.Extensions.Configuration for ServiceMo…
…del (#7) * Add integration with Microsoft.Extensions.Configuration * Added strong typed EndpointAddress
- Loading branch information
Showing
22 changed files
with
889 additions
and
35 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
23 changes: 23 additions & 0 deletions
23
...ServiceModel/MultipleEndpointsWithConfiguration/MultipleEndpointsWithConfiguration.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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net47</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\ServiceModel\ServiceModel.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.ServiceModel" /> | ||
</ItemGroup> | ||
|
||
</Project> |
78 changes: 78 additions & 0 deletions
78
samples/ServiceModel/MultipleEndpointsWithConfiguration/Program.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,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ServiceModel; | ||
using System.Threading.Tasks; | ||
using EMG.Utilities.ServiceModel; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Samples | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
// NamedPipe | ||
["Sample:WCF:Endpoints:NamedPipe:Path"] = "test", | ||
// BasicHttp | ||
["Sample:WCF:Endpoints:BasicHttp:Host"] = "localhost", | ||
["Sample:WCF:Endpoints:BasicHttp:Port"] = "10001", | ||
["Sample:WCF:Endpoints:BasicHttp:Path"] = "test", | ||
// NetTcp | ||
["Sample:WCF:Endpoints:NetTcp:Host"] = "localhost", | ||
["Sample:WCF:Endpoints:NetTcp:Port"] = "10000", | ||
["Sample:WCF:Endpoints:NetTcp:Path"] = "test" | ||
}; | ||
|
||
var configurationBuilder = new ConfigurationBuilder(); | ||
configurationBuilder.AddInMemoryCollection(settings); | ||
|
||
var configuration = configurationBuilder.Build(); | ||
|
||
var services = new ServiceCollection(); | ||
|
||
services.AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Trace)); | ||
|
||
services.AddWcfService<TestService>(service => | ||
{ | ||
service.AddNamedPipeEndpoint(typeof(ITestService), configuration.GetSection("Sample:WCF:Endpoints:NamedPipe").GetNamedPipeEndpointAddress()); | ||
|
||
service.AddBasicHttpEndpoint(typeof(ITestService), configuration.GetSection("Sample:WCF:Endpoints:BasicHttp").GetBasicHttpEndpointAddress()); | ||
|
||
service.AddNetTcpEndpoint(typeof(ITestService), configuration.GetSection("Sample:WCF:Endpoints:NetTcp").GetNetTcpEndpointAddress()); | ||
|
||
service.AddMetadataEndpoints(); | ||
}); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var hostedService = serviceProvider.GetService<IHostedService>(); | ||
|
||
await hostedService.StartAsync(default); | ||
|
||
Console.WriteLine("Press ENTER to exit..."); | ||
Console.ReadLine(); | ||
|
||
await hostedService.StopAsync(default); | ||
} | ||
} | ||
|
||
[ServiceContract] | ||
public interface ITestService | ||
{ | ||
[OperationContract] | ||
Task DoSomethingAsync(); | ||
} | ||
|
||
public class TestService : ITestService | ||
{ | ||
public async Task DoSomethingAsync() | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(1)); | ||
} | ||
} | ||
} |
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
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.Tasks; | ||
using EMG.Utilities.ServiceModel; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using EndpointAddress = EMG.Utilities.ServiceModel.Configuration.EndpointAddress; | ||
|
||
namespace Samples | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Trace)); | ||
|
||
services.AddWcfService<TestService>(service => | ||
{ | ||
service.AddWSHttpEndpoint(typeof(ITestService), EndpointAddress.ForHttp(port: 10001, path:"test")); | ||
|
||
service.AddSecureWSHttpEndpoint(typeof(ITestService), EndpointAddress.ForHttp(port: 10002, path: "test")); | ||
|
||
service.AddMetadataEndpoints(); | ||
}); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var hostedService = serviceProvider.GetService<IHostedService>(); | ||
|
||
await hostedService.StartAsync(default); | ||
|
||
Console.WriteLine("Press ENTER to exit..."); | ||
Console.ReadLine(); | ||
|
||
await hostedService.StopAsync(default); | ||
} | ||
} | ||
|
||
[ServiceContract] | ||
public interface ITestService | ||
{ | ||
[OperationContract] | ||
Task DoSomethingAsync(); | ||
} | ||
|
||
public class TestService : ITestService | ||
{ | ||
public async Task DoSomethingAsync() | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(1)); | ||
} | ||
} | ||
|
||
} |
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net47</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\ServiceModel\ServiceModel.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" /> | ||
</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
Oops, something went wrong.