Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Error Logging Sample #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Extensibility/ErrorHandling/ErrorLogging/Client/Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Using Include="CoreWcf.Samples.ErrorLogging" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.ServiceModel.Http" Version="4.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

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<int> 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<int> 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<int> 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<int> 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<int> 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>, CoreWcf.Samples.ErrorLogging.ICalculatorService
{

/// <summary>
/// Implement this partial method to configure the service endpoint.
/// </summary>
/// <param name="serviceEndpoint">The endpoint to configure</param>
/// <param name="clientCredentials">The client credentials</param>
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<int> 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<int> 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<int> 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<int> 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<int> 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.IAsyncResult>(((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,
}
}
}
69 changes: 69 additions & 0 deletions Extensibility/ErrorHandling/ErrorLogging/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -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 <ENTER> to terminate client.");
Console.ReadLine();
Original file line number Diff line number Diff line change
@@ -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
Loading