Skip to content

Commit d510d75

Browse files
committed
add ILogger
Add Error Logging Sample
1 parent 2078717 commit d510d75

File tree

13 files changed

+586
-0
lines changed

13 files changed

+586
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Using Include="CoreWcf.Samples.ErrorLogging" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="System.ServiceModel.Http" Version="4.*" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"ExtendedData": {
3+
"inputs": [
4+
"http://localhost:5000/CalculatorService/basicHttp?singleWsdl"
5+
],
6+
"collectionTypes": [
7+
"System.Array",
8+
"System.Collections.Generic.Dictionary`2"
9+
],
10+
"namespaceMappings": [
11+
"*, CoreWcf.Samples.ErrorLogging"
12+
],
13+
"sync": true,
14+
"targetFramework": "net6.0",
15+
"typeReuseMode": "All"
16+
}
17+
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
namespace CoreWcf.Samples.ErrorLogging
11+
{
12+
13+
14+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
15+
[System.ServiceModel.ServiceContractAttribute(Namespace="http://CoreWcf.Samples.ErrorLogging", ConfigurationName="CoreWcf.Samples.ErrorLogging.ICalculatorService")]
16+
public interface ICalculatorService
17+
{
18+
19+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Add", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/AddResponse")]
20+
int Add(int n1, int n2);
21+
22+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Add", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/AddResponse")]
23+
System.Threading.Tasks.Task<int> AddAsync(int n1, int n2);
24+
25+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Subtract", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/SubtractResponse")]
26+
int Subtract(int n1, int n2);
27+
28+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Subtract", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/SubtractResponse")]
29+
System.Threading.Tasks.Task<int> SubtractAsync(int n1, int n2);
30+
31+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Multiply", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/MultiplyResponse")]
32+
int Multiply(int n1, int n2);
33+
34+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Multiply", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/MultiplyResponse")]
35+
System.Threading.Tasks.Task<int> MultiplyAsync(int n1, int n2);
36+
37+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Divide", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/DivideResponse")]
38+
int Divide(int n1, int n2);
39+
40+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Divide", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/DivideResponse")]
41+
System.Threading.Tasks.Task<int> DivideAsync(int n1, int n2);
42+
43+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Factorial", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/FactorialResponse")]
44+
int Factorial(int n);
45+
46+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/Factorial", ReplyAction="http://CoreWcf.Samples.ErrorLogging/ICalculatorService/FactorialResponse")]
47+
System.Threading.Tasks.Task<int> FactorialAsync(int n);
48+
}
49+
50+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
51+
public interface ICalculatorServiceChannel : CoreWcf.Samples.ErrorLogging.ICalculatorService, System.ServiceModel.IClientChannel
52+
{
53+
}
54+
55+
[System.Diagnostics.DebuggerStepThroughAttribute()]
56+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
57+
public partial class CalculatorServiceClient : System.ServiceModel.ClientBase<CoreWcf.Samples.ErrorLogging.ICalculatorService>, CoreWcf.Samples.ErrorLogging.ICalculatorService
58+
{
59+
60+
/// <summary>
61+
/// Implement this partial method to configure the service endpoint.
62+
/// </summary>
63+
/// <param name="serviceEndpoint">The endpoint to configure</param>
64+
/// <param name="clientCredentials">The client credentials</param>
65+
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
66+
67+
public CalculatorServiceClient() :
68+
base(CalculatorServiceClient.GetDefaultBinding(), CalculatorServiceClient.GetDefaultEndpointAddress())
69+
{
70+
this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_ICalculatorService.ToString();
71+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
72+
}
73+
74+
public CalculatorServiceClient(EndpointConfiguration endpointConfiguration) :
75+
base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), CalculatorServiceClient.GetEndpointAddress(endpointConfiguration))
76+
{
77+
this.Endpoint.Name = endpointConfiguration.ToString();
78+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
79+
}
80+
81+
public CalculatorServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
82+
base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
83+
{
84+
this.Endpoint.Name = endpointConfiguration.ToString();
85+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
86+
}
87+
88+
public CalculatorServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
89+
base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
90+
{
91+
this.Endpoint.Name = endpointConfiguration.ToString();
92+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
93+
}
94+
95+
public CalculatorServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
96+
base(binding, remoteAddress)
97+
{
98+
}
99+
100+
public int Add(int n1, int n2)
101+
{
102+
return base.Channel.Add(n1, n2);
103+
}
104+
105+
public System.Threading.Tasks.Task<int> AddAsync(int n1, int n2)
106+
{
107+
return base.Channel.AddAsync(n1, n2);
108+
}
109+
110+
public int Subtract(int n1, int n2)
111+
{
112+
return base.Channel.Subtract(n1, n2);
113+
}
114+
115+
public System.Threading.Tasks.Task<int> SubtractAsync(int n1, int n2)
116+
{
117+
return base.Channel.SubtractAsync(n1, n2);
118+
}
119+
120+
public int Multiply(int n1, int n2)
121+
{
122+
return base.Channel.Multiply(n1, n2);
123+
}
124+
125+
public System.Threading.Tasks.Task<int> MultiplyAsync(int n1, int n2)
126+
{
127+
return base.Channel.MultiplyAsync(n1, n2);
128+
}
129+
130+
public int Divide(int n1, int n2)
131+
{
132+
return base.Channel.Divide(n1, n2);
133+
}
134+
135+
public System.Threading.Tasks.Task<int> DivideAsync(int n1, int n2)
136+
{
137+
return base.Channel.DivideAsync(n1, n2);
138+
}
139+
140+
public int Factorial(int n)
141+
{
142+
return base.Channel.Factorial(n);
143+
}
144+
145+
public System.Threading.Tasks.Task<int> FactorialAsync(int n)
146+
{
147+
return base.Channel.FactorialAsync(n);
148+
}
149+
150+
public virtual System.Threading.Tasks.Task OpenAsync()
151+
{
152+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
153+
}
154+
155+
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
156+
{
157+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService))
158+
{
159+
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
160+
result.MaxBufferSize = int.MaxValue;
161+
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
162+
result.MaxReceivedMessageSize = int.MaxValue;
163+
result.AllowCookies = true;
164+
return result;
165+
}
166+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
167+
}
168+
169+
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
170+
{
171+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService))
172+
{
173+
return new System.ServiceModel.EndpointAddress("http://localhost:5000/CalculatorService/basicHttp");
174+
}
175+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
176+
}
177+
178+
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
179+
{
180+
return CalculatorServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_ICalculatorService);
181+
}
182+
183+
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
184+
{
185+
return CalculatorServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_ICalculatorService);
186+
}
187+
188+
public enum EndpointConfiguration
189+
{
190+
191+
BasicHttpBinding_ICalculatorService,
192+
}
193+
}
194+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
//The service contract is defined using Connected Service "WCF Web Service", generated from the service by the dotnet svcutil tool.
5+
6+
//Client implementation code.
7+
using System.ServiceModel;
8+
9+
// Create a client with given client endpoint configuration
10+
CalculatorServiceClient client = new CalculatorServiceClient();
11+
12+
// Call the Add service operation
13+
int value1 = 15;
14+
int value2 = 3;
15+
int result = client.Add(value1, value2);
16+
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
17+
18+
// Call the Subtract service operation
19+
value1 = 145;
20+
value2 = 76;
21+
result = client.Subtract(value1, value2);
22+
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
23+
24+
// Call the Multiply service operation
25+
value1 = 9;
26+
value2 = 81;
27+
result = client.Multiply(value1, value2);
28+
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
29+
30+
try
31+
{
32+
Console.WriteLine("Forcing an error in Divide");
33+
// Call the Divide service operation - trigger a divide by zero error
34+
value1 = 22;
35+
value2 = 0;
36+
result = client.Divide(value1, value2);
37+
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
38+
}
39+
catch (FaultException e)
40+
{
41+
Console.WriteLine("FaultException: " + e.GetType().Name + " - " + e.Message);
42+
}
43+
catch (Exception e)
44+
{
45+
Console.WriteLine("Exception: " + e.GetType().Name + " - " + e.Message);
46+
}
47+
48+
try
49+
{
50+
// Call the Factorial service operation - trigger an overflow error
51+
Console.WriteLine("Forcing an error in Factorial");
52+
value1 = 0;
53+
result = client.Factorial(value1);
54+
Console.WriteLine("Factorial({0}) = {1}", value1, result);
55+
}
56+
catch (FaultException e)
57+
{
58+
Console.WriteLine("FaultException: " + e.GetType().Name + " - " + e.Message);
59+
}
60+
catch (Exception e)
61+
{
62+
Console.WriteLine("Exception: " + e.GetType().Name + " - " + e.Message);
63+
}
64+
65+
client.Close();
66+
67+
Console.WriteLine();
68+
Console.WriteLine("Press <ENTER> to terminate client.");
69+
Console.ReadLine();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.2.32422.2
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service", "Service\Service.csproj", "{BF126326-3393-407C-B24A-8FCCC388BE27}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{B533CADA-93BB-40E1-8FBA-FE37100062C3}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{BF126326-3393-407C-B24A-8FCCC388BE27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{BF126326-3393-407C-B24A-8FCCC388BE27}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{BF126326-3393-407C-B24A-8FCCC388BE27}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{BF126326-3393-407C-B24A-8FCCC388BE27}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{B533CADA-93BB-40E1-8FBA-FE37100062C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{B533CADA-93BB-40E1-8FBA-FE37100062C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{B533CADA-93BB-40E1-8FBA-FE37100062C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{B533CADA-93BB-40E1-8FBA-FE37100062C3}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {AD996EFD-70DC-4431-B411-5A2771DD02D3}
30+
EndGlobalSection
31+
EndGlobal

0 commit comments

Comments
 (0)