Skip to content

Commit 01aa23f

Browse files
committed
Add Getting Started Sample
1 parent 2078717 commit 01aa23f

File tree

12 files changed

+416
-0
lines changed

12 files changed

+416
-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.GettingStarted" />
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?wsdl"
5+
],
6+
"collectionTypes": [
7+
"System.Array",
8+
"System.Collections.Generic.Dictionary`2"
9+
],
10+
"namespaceMappings": [
11+
"*, CoreWcf.Samples.GettingStarted"
12+
],
13+
"sync": true,
14+
"targetFramework": "net6.0",
15+
"typeReuseMode": "All"
16+
}
17+
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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.GettingStarted
11+
{
12+
13+
14+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
15+
[System.ServiceModel.ServiceContractAttribute(Namespace="http://CoreWcf.Samples.GettingStarted", ConfigurationName="CoreWcf.Samples.GettingStarted.ICalculatorService")]
16+
public interface ICalculatorService
17+
{
18+
19+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.GettingStarted/ICalculatorService/Add", ReplyAction="http://CoreWcf.Samples.GettingStarted/ICalculatorService/AddResponse")]
20+
double Add(double n1, double n2);
21+
22+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.GettingStarted/ICalculatorService/Add", ReplyAction="http://CoreWcf.Samples.GettingStarted/ICalculatorService/AddResponse")]
23+
System.Threading.Tasks.Task<double> AddAsync(double n1, double n2);
24+
25+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.GettingStarted/ICalculatorService/Subtract", ReplyAction="http://CoreWcf.Samples.GettingStarted/ICalculatorService/SubtractResponse")]
26+
double Subtract(double n1, double n2);
27+
28+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.GettingStarted/ICalculatorService/Subtract", ReplyAction="http://CoreWcf.Samples.GettingStarted/ICalculatorService/SubtractResponse")]
29+
System.Threading.Tasks.Task<double> SubtractAsync(double n1, double n2);
30+
31+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.GettingStarted/ICalculatorService/Multiply", ReplyAction="http://CoreWcf.Samples.GettingStarted/ICalculatorService/MultiplyResponse")]
32+
double Multiply(double n1, double n2);
33+
34+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.GettingStarted/ICalculatorService/Multiply", ReplyAction="http://CoreWcf.Samples.GettingStarted/ICalculatorService/MultiplyResponse")]
35+
System.Threading.Tasks.Task<double> MultiplyAsync(double n1, double n2);
36+
37+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.GettingStarted/ICalculatorService/Divide", ReplyAction="http://CoreWcf.Samples.GettingStarted/ICalculatorService/DivideResponse")]
38+
double Divide(double n1, double n2);
39+
40+
[System.ServiceModel.OperationContractAttribute(Action="http://CoreWcf.Samples.GettingStarted/ICalculatorService/Divide", ReplyAction="http://CoreWcf.Samples.GettingStarted/ICalculatorService/DivideResponse")]
41+
System.Threading.Tasks.Task<double> DivideAsync(double n1, double n2);
42+
}
43+
44+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
45+
public interface ICalculatorServiceChannel : CoreWcf.Samples.GettingStarted.ICalculatorService, System.ServiceModel.IClientChannel
46+
{
47+
}
48+
49+
[System.Diagnostics.DebuggerStepThroughAttribute()]
50+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
51+
public partial class CalculatorServiceClient : System.ServiceModel.ClientBase<CoreWcf.Samples.GettingStarted.ICalculatorService>, CoreWcf.Samples.GettingStarted.ICalculatorService
52+
{
53+
54+
/// <summary>
55+
/// Implement this partial method to configure the service endpoint.
56+
/// </summary>
57+
/// <param name="serviceEndpoint">The endpoint to configure</param>
58+
/// <param name="clientCredentials">The client credentials</param>
59+
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
60+
61+
public CalculatorServiceClient() :
62+
base(CalculatorServiceClient.GetDefaultBinding(), CalculatorServiceClient.GetDefaultEndpointAddress())
63+
{
64+
this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_ICalculatorService.ToString();
65+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
66+
}
67+
68+
public CalculatorServiceClient(EndpointConfiguration endpointConfiguration) :
69+
base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), CalculatorServiceClient.GetEndpointAddress(endpointConfiguration))
70+
{
71+
this.Endpoint.Name = endpointConfiguration.ToString();
72+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
73+
}
74+
75+
public CalculatorServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
76+
base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
77+
{
78+
this.Endpoint.Name = endpointConfiguration.ToString();
79+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
80+
}
81+
82+
public CalculatorServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
83+
base(CalculatorServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
84+
{
85+
this.Endpoint.Name = endpointConfiguration.ToString();
86+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
87+
}
88+
89+
public CalculatorServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
90+
base(binding, remoteAddress)
91+
{
92+
}
93+
94+
public double Add(double n1, double n2)
95+
{
96+
return base.Channel.Add(n1, n2);
97+
}
98+
99+
public System.Threading.Tasks.Task<double> AddAsync(double n1, double n2)
100+
{
101+
return base.Channel.AddAsync(n1, n2);
102+
}
103+
104+
public double Subtract(double n1, double n2)
105+
{
106+
return base.Channel.Subtract(n1, n2);
107+
}
108+
109+
public System.Threading.Tasks.Task<double> SubtractAsync(double n1, double n2)
110+
{
111+
return base.Channel.SubtractAsync(n1, n2);
112+
}
113+
114+
public double Multiply(double n1, double n2)
115+
{
116+
return base.Channel.Multiply(n1, n2);
117+
}
118+
119+
public System.Threading.Tasks.Task<double> MultiplyAsync(double n1, double n2)
120+
{
121+
return base.Channel.MultiplyAsync(n1, n2);
122+
}
123+
124+
public double Divide(double n1, double n2)
125+
{
126+
return base.Channel.Divide(n1, n2);
127+
}
128+
129+
public System.Threading.Tasks.Task<double> DivideAsync(double n1, double n2)
130+
{
131+
return base.Channel.DivideAsync(n1, n2);
132+
}
133+
134+
public virtual System.Threading.Tasks.Task OpenAsync()
135+
{
136+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
137+
}
138+
139+
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
140+
{
141+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService))
142+
{
143+
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
144+
result.MaxBufferSize = int.MaxValue;
145+
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
146+
result.MaxReceivedMessageSize = int.MaxValue;
147+
result.AllowCookies = true;
148+
return result;
149+
}
150+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
151+
}
152+
153+
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
154+
{
155+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService))
156+
{
157+
return new System.ServiceModel.EndpointAddress("http://localhost:5000/CalculatorService");
158+
}
159+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
160+
}
161+
162+
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
163+
{
164+
return CalculatorServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_ICalculatorService);
165+
}
166+
167+
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
168+
{
169+
return CalculatorServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_ICalculatorService);
170+
}
171+
172+
public enum EndpointConfiguration
173+
{
174+
175+
BasicHttpBinding_ICalculatorService,
176+
}
177+
}
178+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
CalculatorServiceClient client = new CalculatorServiceClient();
8+
9+
// Call the Add service operation.
10+
double value1 = 100.00D;
11+
double value2 = 15.99D;
12+
double result = client.Add(value1, value2);
13+
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
14+
15+
// Call the Subtract service operation.
16+
value1 = 145.00D;
17+
value2 = 76.54D;
18+
result = client.Subtract(value1, value2);
19+
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
20+
21+
// Call the Multiply service operation.
22+
value1 = 9.00D;
23+
value2 = 81.25D;
24+
result = client.Multiply(value1, value2);
25+
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
26+
27+
// Call the Divide service operation.
28+
value1 = 22.00D;
29+
value2 = 7.00D;
30+
result = client.Divide(value1, value2);
31+
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
32+
33+
//Closing the client gracefully closes the connection and cleans up resources
34+
client.CloseAsync();
35+
36+
Console.WriteLine();
37+
Console.WriteLine("Press <ENTER> to terminate client.");
38+
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
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace CoreWcf.Samples.GettingStarted
2+
{
3+
// Service class which implements the service contract interface.
4+
public class CalculatorService : ICalculatorService
5+
{
6+
public double Add(double n1, double n2)
7+
{
8+
return n1 + n2;
9+
}
10+
11+
public double Subtract(double n1, double n2)
12+
{
13+
return n1 - n2;
14+
}
15+
16+
public double Multiply(double n1, double n2)
17+
{
18+
return n1 * n2;
19+
}
20+
21+
public double Divide(double n1, double n2)
22+
{
23+
return n1 / n2;
24+
}
25+
}
26+
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace CoreWcf.Samples.GettingStarted
2+
{
3+
// Define a service contract.
4+
[ServiceContract(Namespace = "http://CoreWcf.Samples.GettingStarted")]
5+
public interface ICalculatorService
6+
{
7+
[OperationContract]
8+
double Add(double n1, double n2);
9+
[OperationContract]
10+
double Subtract(double n1, double n2);
11+
[OperationContract]
12+
double Multiply(double n1, double n2);
13+
[OperationContract]
14+
double Divide(double n1, double n2);
15+
}
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
var builder = WebApplication.CreateBuilder();
5+
6+
//Enable CoreWCF Services, with metadata (WSDL) support
7+
builder.Services.AddServiceModelServices()
8+
.AddServiceModelMetadata()
9+
.AddSingleton<IServiceBehavior, UseRequestHeadersForMetadataAddressBehavior>();
10+
11+
var app = builder.Build();
12+
13+
app.UseServiceModel(builder =>
14+
{
15+
// Add the Calculator Service
16+
builder.AddService<CalculatorService>(serviceOptions => { })
17+
// Add BasicHttpBinding endpoint
18+
.AddServiceEndpoint<CalculatorService, ICalculatorService>(new BasicHttpBinding(), "CalculatorService");
19+
20+
// Configure WSDL to be available
21+
var serviceMetadataBehavior = app.Services.GetRequiredService<ServiceMetadataBehavior>();
22+
serviceMetadataBehavior.HttpGetEnabled = true;
23+
});
24+
25+
app.Run();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:57029/CalculatorService",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"Service": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"launchUrl": "http://localhost:5000/CalculatorService",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"IIS Express": {
21+
"commandName": "IISExpress",
22+
"launchBrowser": true,
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)