From d510d75e7cb32a03abac260301b903b89293ea69 Mon Sep 17 00:00:00 2001 From: Abdelwahab Afifi Date: Tue, 16 May 2023 02:56:19 +0300 Subject: [PATCH] add ILogger Add Error Logging Sample --- .../ErrorLogging/Client/Client.csproj | 18 ++ .../ConnectedService.json | 17 ++ .../CoreWcf.Samples.ErrorLogging/Reference.cs | 194 ++++++++++++++++++ .../ErrorLogging/Client/Program.cs | 69 +++++++ ...tensibility.ErrorHandling.ErrorLogging.sln | 31 +++ .../ErrorLogging/Service/CalculatorService.cs | 122 +++++++++++ .../Service/ICalculatorService.cs | 25 +++ .../ErrorLogging/Service/Program.cs | 30 +++ .../Service/Properties/launchSettings.json | 13 ++ .../ErrorLogging/Service/Service.csproj | 21 ++ .../Service/ServiceProviderServiceBehavior.cs | 29 +++ .../Service/appsettings.Development.json | 8 + .../ErrorLogging/Service/appsettings.json | 9 + 13 files changed, 586 insertions(+) create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Client/Client.csproj create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Client/Connected Services/CoreWcf.Samples.ErrorLogging/ConnectedService.json create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Client/Connected Services/CoreWcf.Samples.ErrorLogging/Reference.cs create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Client/Program.cs create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Extensibility.ErrorHandling.ErrorLogging.sln create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Service/CalculatorService.cs create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Service/ICalculatorService.cs create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Service/Program.cs create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Service/Properties/launchSettings.json create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Service/Service.csproj create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Service/ServiceProviderServiceBehavior.cs create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Service/appsettings.Development.json create mode 100644 Extensibility/ErrorHandling/ErrorLogging/Service/appsettings.json diff --git a/Extensibility/ErrorHandling/ErrorLogging/Client/Client.csproj b/Extensibility/ErrorHandling/ErrorLogging/Client/Client.csproj new file mode 100644 index 0000000..fe6787a --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Client/Client.csproj @@ -0,0 +1,18 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Extensibility/ErrorHandling/ErrorLogging/Client/Connected Services/CoreWcf.Samples.ErrorLogging/ConnectedService.json b/Extensibility/ErrorHandling/ErrorLogging/Client/Connected Services/CoreWcf.Samples.ErrorLogging/ConnectedService.json new file mode 100644 index 0000000..0143b22 --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Client/Connected Services/CoreWcf.Samples.ErrorLogging/ConnectedService.json @@ -0,0 +1,17 @@ +{ + "ExtendedData": { + "inputs": [ + "http://localhost:5000/CalculatorService/basicHttp?singleWsdl" + ], + "collectionTypes": [ + "System.Array", + "System.Collections.Generic.Dictionary`2" + ], + "namespaceMappings": [ + "*, CoreWcf.Samples.ErrorLogging" + ], + "sync": true, + "targetFramework": "net6.0", + "typeReuseMode": "All" + } +} \ No newline at end of file diff --git a/Extensibility/ErrorHandling/ErrorLogging/Client/Connected Services/CoreWcf.Samples.ErrorLogging/Reference.cs b/Extensibility/ErrorHandling/ErrorLogging/Client/Connected Services/CoreWcf.Samples.ErrorLogging/Reference.cs new file mode 100644 index 0000000..e02efc4 --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Client/Connected Services/CoreWcf.Samples.ErrorLogging/Reference.cs @@ -0,0 +1,194 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CoreWcf.Samples.ErrorLogging +{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")] + [System.ServiceModel.ServiceContractAttribute(Namespace="http://CoreWcf.Samples.ErrorLogging", ConfigurationName="CoreWcf.Samples.ErrorLogging.ICalculatorService")] + public interface ICalculatorService + { + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Add", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/AddResponse")] + int Add(int n1, int n2); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Add", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/AddResponse")] + System.Threading.Tasks.Task AddAsync(int n1, int n2); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Subtract", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/SubtractResponse")] + int Subtract(int n1, int n2); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Subtract", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/SubtractResponse")] + System.Threading.Tasks.Task SubtractAsync(int n1, int n2); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Multiply", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/MultiplyResponse")] + int Multiply(int n1, int n2); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Multiply", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/MultiplyResponse")] + System.Threading.Tasks.Task MultiplyAsync(int n1, int n2); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Divide", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/DivideResponse")] + int Divide(int n1, int n2); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Divide", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/DivideResponse")] + System.Threading.Tasks.Task DivideAsync(int n1, int n2); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Factorial", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/FactorialResponse")] + int Factorial(int n); + + [System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Factorial", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/FactorialResponse")] + System.Threading.Tasks.Task FactorialAsync(int n); + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")] + public interface ICalculatorServiceChannel : CoreWcf.Samples.ErrorLogging.ICalculatorService, System.ServiceModel.IClientChannel + { + } + + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")] + public partial class CalculatorServiceClient : System.ServiceModel.ClientBase, CoreWcf.Samples.ErrorLogging.ICalculatorService + { + + /// + /// Implement this partial method to configure the service endpoint. + /// + /// The endpoint to configure + /// The client credentials + static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials); + + public CalculatorServiceClient() : + base(CalculatorServiceClient.GetDefaultBinding(), CalculatorServiceClient.GetDefaultEndpointAddress()) + { + this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_ICalculatorService.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public CalculatorServiceClient(EndpointConfiguration endpointConfiguration) : + base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), CalculatorServiceClient.GetEndpointAddress(endpointConfiguration)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public CalculatorServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) : + base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public CalculatorServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : + base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public CalculatorServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : + base(binding, remoteAddress) + { + } + + public int Add(int n1, int n2) + { + return base.Channel.Add(n1, n2); + } + + public System.Threading.Tasks.Task AddAsync(int n1, int n2) + { + return base.Channel.AddAsync(n1, n2); + } + + public int Subtract(int n1, int n2) + { + return base.Channel.Subtract(n1, n2); + } + + public System.Threading.Tasks.Task SubtractAsync(int n1, int n2) + { + return base.Channel.SubtractAsync(n1, n2); + } + + public int Multiply(int n1, int n2) + { + return base.Channel.Multiply(n1, n2); + } + + public System.Threading.Tasks.Task MultiplyAsync(int n1, int n2) + { + return base.Channel.MultiplyAsync(n1, n2); + } + + public int Divide(int n1, int n2) + { + return base.Channel.Divide(n1, n2); + } + + public System.Threading.Tasks.Task DivideAsync(int n1, int n2) + { + return base.Channel.DivideAsync(n1, n2); + } + + public int Factorial(int n) + { + return base.Channel.Factorial(n); + } + + public System.Threading.Tasks.Task FactorialAsync(int n) + { + return base.Channel.FactorialAsync(n); + } + + public virtual System.Threading.Tasks.Task OpenAsync() + { + return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndOpen)); + } + + private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService)) + { + System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(); + result.MaxBufferSize = int.MaxValue; + result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; + result.MaxReceivedMessageSize = int.MaxValue; + result.AllowCookies = true; + return result; + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService)) + { + return new System.ServiceModel.EndpointAddress("http://localhost:5000/CalculatorService/basicHttp"); + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.Channels.Binding GetDefaultBinding() + { + return CalculatorServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_ICalculatorService); + } + + private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress() + { + return CalculatorServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_ICalculatorService); + } + + public enum EndpointConfiguration + { + + BasicHttpBinding_ICalculatorService, + } + } +} diff --git a/Extensibility/ErrorHandling/ErrorLogging/Client/Program.cs b/Extensibility/ErrorHandling/ErrorLogging/Client/Program.cs new file mode 100644 index 0000000..49f65ef --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Client/Program.cs @@ -0,0 +1,69 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +//The service contract is defined using Connected Service "WCF Web Service", generated from the service by the dotnet svcutil tool. + +//Client implementation code. +using System.ServiceModel; + +// Create a client with given client endpoint configuration +CalculatorServiceClient client = new CalculatorServiceClient(); + +// Call the Add service operation +int value1 = 15; +int value2 = 3; +int result = client.Add(value1, value2); +Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); + +// Call the Subtract service operation +value1 = 145; +value2 = 76; +result = client.Subtract(value1, value2); +Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); + +// Call the Multiply service operation +value1 = 9; +value2 = 81; +result = client.Multiply(value1, value2); +Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); + +try +{ + Console.WriteLine("Forcing an error in Divide"); + // Call the Divide service operation - trigger a divide by zero error + value1 = 22; + value2 = 0; + result = client.Divide(value1, value2); + Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); +} +catch (FaultException e) +{ + Console.WriteLine("FaultException: " + e.GetType().Name + " - " + e.Message); +} +catch (Exception e) +{ + Console.WriteLine("Exception: " + e.GetType().Name + " - " + e.Message); +} + +try +{ + // Call the Factorial service operation - trigger an overflow error + Console.WriteLine("Forcing an error in Factorial"); + value1 = 0; + result = client.Factorial(value1); + Console.WriteLine("Factorial({0}) = {1}", value1, result); +} +catch (FaultException e) +{ + Console.WriteLine("FaultException: " + e.GetType().Name + " - " + e.Message); +} +catch (Exception e) +{ + Console.WriteLine("Exception: " + e.GetType().Name + " - " + e.Message); +} + +client.Close(); + +Console.WriteLine(); +Console.WriteLine("Press to terminate client."); +Console.ReadLine(); diff --git a/Extensibility/ErrorHandling/ErrorLogging/Extensibility.ErrorHandling.ErrorLogging.sln b/Extensibility/ErrorHandling/ErrorLogging/Extensibility.ErrorHandling.ErrorLogging.sln new file mode 100644 index 0000000..359b903 --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Extensibility.ErrorHandling.ErrorLogging.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32422.2 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service", "Service\Service.csproj", "{BF126326-3393-407C-B24A-8FCCC388BE27}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{B533CADA-93BB-40E1-8FBA-FE37100062C3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BF126326-3393-407C-B24A-8FCCC388BE27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BF126326-3393-407C-B24A-8FCCC388BE27}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BF126326-3393-407C-B24A-8FCCC388BE27}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BF126326-3393-407C-B24A-8FCCC388BE27}.Release|Any CPU.Build.0 = Release|Any CPU + {B533CADA-93BB-40E1-8FBA-FE37100062C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B533CADA-93BB-40E1-8FBA-FE37100062C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B533CADA-93BB-40E1-8FBA-FE37100062C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B533CADA-93BB-40E1-8FBA-FE37100062C3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AD996EFD-70DC-4431-B411-5A2771DD02D3} + EndGlobalSection +EndGlobal diff --git a/Extensibility/ErrorHandling/ErrorLogging/Service/CalculatorService.cs b/Extensibility/ErrorHandling/ErrorLogging/Service/CalculatorService.cs new file mode 100644 index 0000000..132cb93 --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Service/CalculatorService.cs @@ -0,0 +1,122 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using CoreWCF.Channels; +using CoreWCF.Dispatcher; + +namespace CoreWcf.Samples.ErrorLogging +{ + // Service class which implements the service contract interface. + //The ErrorBehaviorAttribute is used to install the custom error handler. + [ErrorBehavior(typeof(CalculatorErrorHandler))] + public class CalculatorService : ICalculatorService + { + public int Add(int n1, int n2) + { + return n1 + n2; + } + + public int Subtract(int n1, int n2) + { + return n1 - n2; + } + + public int Multiply(int n1, int n2) + { + return n1 * n2; + } + + public int Divide(int n1, int n2) + { + try + { + return n1 / n2; + } + catch (DivideByZeroException) + { + throw new FaultException("Invalid Argument: The second argument must not be zero."); + } + } + + public int Factorial(int n) + { + if (n < 1) + throw new FaultException("Invalid Argument: The argument must be greater than zero."); + + int factorial = 1; + for (int i = 1; i <= n; i++) + { + factorial = factorial * i; + } + return factorial; + } + } + + public class CalculatorErrorHandler : IErrorHandler + { + private ILogger _logger; + // Provide a fault. The Message fault parameter can be replaced, or set to + // null to suppress reporting a fault. + public CalculatorErrorHandler(ILogger logger) + { + _logger = logger; + } + + public void ProvideFault(Exception error, MessageVersion version, ref Message fault) + { + } + + // HandleError. Log an error, then allow the error to be handled as usual. + // Return true if the error is considered as already handled + public bool HandleError(Exception error) + { + _logger.LogInformation("Exception: " + error.GetType().Name + " - " + error.Message); + + return true; + } + } + + // This attribute can be used to install a custom error handler for a service + public sealed class ErrorBehaviorAttribute : Attribute, IServiceBehavior + { + public ErrorBehaviorAttribute(Type errorHandlerType) + { + ErrorHandlerType = errorHandlerType; + } + + public Type ErrorHandlerType { get; } + + void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase) + { + } + + void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection endpoints, BindingParameterCollection parameters) + { + } + + void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase) + { + IErrorHandler errorHandler; + var serviceProvider = description.Behaviors.Find().ServiceProvider; + + try + { + errorHandler = (IErrorHandler)ActivatorUtilities.CreateInstance(serviceProvider, ErrorHandlerType); + } + catch (MissingMethodException e) + { + throw new ArgumentException("The errorHandlerType specified in the ErrorBehaviorAttribute constructor must have a public empty constructor.", e); + } + catch (InvalidCastException e) + { + throw new ArgumentException("The errorHandlerType specified in the ErrorBehaviorAttribute constructor must implement CoreWCF.Dispatcher.IErrorHandler.", e); + } + + foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers) + { + ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher; + channelDispatcher.ErrorHandlers.Add(errorHandler); + } + } + } +} diff --git a/Extensibility/ErrorHandling/ErrorLogging/Service/ICalculatorService.cs b/Extensibility/ErrorHandling/ErrorLogging/Service/ICalculatorService.cs new file mode 100644 index 0000000..2f82989 --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Service/ICalculatorService.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace CoreWcf.Samples.ErrorLogging +{ + // Define a service contract + [ServiceContract(Namespace = "http://CoreWcf.Samples.ErrorLogging")] + public interface ICalculatorService + { + [OperationContract] + int Add(int n1, int n2); + + [OperationContract] + int Subtract(int n1, int n2); + + [OperationContract] + int Multiply(int n1, int n2); + + [OperationContract] + int Divide(int n1, int n2); + + [OperationContract] + int Factorial(int n); + } +} diff --git a/Extensibility/ErrorHandling/ErrorLogging/Service/Program.cs b/Extensibility/ErrorHandling/ErrorLogging/Service/Program.cs new file mode 100644 index 0000000..9a6a8dd --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Service/Program.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +var builder = WebApplication.CreateBuilder(); + +//Enable CoreWCF Services, with metadata (WSDL) support +builder.Services.AddServiceModelServices() + .AddServiceModelMetadata() + .AddSingleton() + .AddSingleton(); + +//Add logging +builder.Logging.ClearProviders(); +builder.Logging.AddConsole(); + +var app = builder.Build(); + +app.UseServiceModel(builder => +{ + // Add the Calculator Service + builder.AddService(serviceOptions => { }) + // Add BasicHttpBinding endpoint + .AddServiceEndpoint(new BasicHttpBinding(), "CalculatorService/basicHttp"); + + // Configure WSDL to be available + var serviceMetadataBehavior = app.Services.GetRequiredService(); + serviceMetadataBehavior.HttpGetEnabled = true; +}); + +app.Run(); diff --git a/Extensibility/ErrorHandling/ErrorLogging/Service/Properties/launchSettings.json b/Extensibility/ErrorHandling/ErrorLogging/Service/Properties/launchSettings.json new file mode 100644 index 0000000..844a166 --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Service/Properties/launchSettings.json @@ -0,0 +1,13 @@ +{ + "profiles": { + "Service": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "http://localhost:5000/CalculatorService/basicHttp", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Extensibility/ErrorHandling/ErrorLogging/Service/Service.csproj b/Extensibility/ErrorHandling/ErrorLogging/Service/Service.csproj new file mode 100644 index 0000000..7ceda64 --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Service/Service.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + true + InProcess + + + + + + + + + + + + + + diff --git a/Extensibility/ErrorHandling/ErrorLogging/Service/ServiceProviderServiceBehavior.cs b/Extensibility/ErrorHandling/ErrorLogging/Service/ServiceProviderServiceBehavior.cs new file mode 100644 index 0000000..fdcd9ad --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Service/ServiceProviderServiceBehavior.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.ObjectModel; +using CoreWCF.Channels; + +//this class is used to get ServiceProvider reference as ServiceBehavior for DI +internal class ServiceProviderServiceBehavior : IServiceBehavior +{ + public ServiceProviderServiceBehavior(IServiceProvider serviceProvider) + { + ServiceProvider = serviceProvider; + } + + public IServiceProvider ServiceProvider { get; } + + public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection endpoints, BindingParameterCollection bindingParameters) + { + } + + public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) + { + + } + + public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) + { + } +} diff --git a/Extensibility/ErrorHandling/ErrorLogging/Service/appsettings.Development.json b/Extensibility/ErrorHandling/ErrorLogging/Service/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Service/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Extensibility/ErrorHandling/ErrorLogging/Service/appsettings.json b/Extensibility/ErrorHandling/ErrorLogging/Service/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Extensibility/ErrorHandling/ErrorLogging/Service/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}