Skip to content

Commit 4db4ec4

Browse files
committed
convert to top level-statement app and add license
Add BasicHttpBinding Transport Security Sample - IIS/Kestrel Hosted Updates: 1. Remove CS folder in folder heirarchy 2. Rename .sln file to Binding.Basic.Http.sln 3. Remove .config folder (validate this doesn't break the build) Update Client Connected Service URL Update LaunchSettings and remove .UseIIS (WebHost default) Update Client NuGet Packages Update NuGet pPackages Add BasicHttpBinding Sample - IIS Hosted
1 parent 2078717 commit 4db4ec4

File tree

13 files changed

+460
-0
lines changed

13 files changed

+460
-0
lines changed
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<PackageReference Include="System.ServiceModel.Http" Version="4.*" />
12+
</ItemGroup>
13+
14+
</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+
"https://localhost/CoreWcfSamples/basicHttpTransportSecurity?singleWsdl"
5+
],
6+
"collectionTypes": [
7+
"System.Array",
8+
"System.Collections.Generic.Dictionary`2"
9+
],
10+
"namespaceMappings": [
11+
"*, CoreWcf.Samples.TransportSecurity"
12+
],
13+
"sync": true,
14+
"targetFramework": "net6.0",
15+
"typeReuseMode": "All"
16+
}
17+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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.TransportSecurity
11+
{
12+
13+
14+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3")]
15+
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="CoreWcf.Samples.TransportSecurity.ICalculatorService")]
16+
public interface ICalculatorService
17+
{
18+
19+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Add", ReplyAction="http://tempuri.org/ICalculatorService/AddResponse")]
20+
double Add(double n1, double n2);
21+
22+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Add", ReplyAction="http://tempuri.org/ICalculatorService/AddResponse")]
23+
System.Threading.Tasks.Task<double> AddAsync(double n1, double n2);
24+
25+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Subtract", ReplyAction="http://tempuri.org/ICalculatorService/SubtractResponse")]
26+
double Subtract(double n1, double n2);
27+
28+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Subtract", ReplyAction="http://tempuri.org/ICalculatorService/SubtractResponse")]
29+
System.Threading.Tasks.Task<double> SubtractAsync(double n1, double n2);
30+
31+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Multiply", ReplyAction="http://tempuri.org/ICalculatorService/MultiplyResponse")]
32+
double Multiply(double n1, double n2);
33+
34+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Multiply", ReplyAction="http://tempuri.org/ICalculatorService/MultiplyResponse")]
35+
System.Threading.Tasks.Task<double> MultiplyAsync(double n1, double n2);
36+
37+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Divide", ReplyAction="http://tempuri.org/ICalculatorService/DivideResponse")]
38+
double Divide(double n1, double n2);
39+
40+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Divide", ReplyAction="http://tempuri.org/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.0.3")]
45+
public interface ICalculatorServiceChannel : CoreWcf.Samples.TransportSecurity.ICalculatorService, System.ServiceModel.IClientChannel
46+
{
47+
}
48+
49+
[System.Diagnostics.DebuggerStepThroughAttribute()]
50+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3")]
51+
public partial class CalculatorServiceClient : System.ServiceModel.ClientBase<CoreWcf.Samples.TransportSecurity.ICalculatorService>, CoreWcf.Samples.TransportSecurity.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+
public virtual System.Threading.Tasks.Task CloseAsync()
140+
{
141+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
142+
}
143+
144+
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
145+
{
146+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService))
147+
{
148+
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
149+
result.MaxBufferSize = int.MaxValue;
150+
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
151+
result.MaxReceivedMessageSize = int.MaxValue;
152+
result.AllowCookies = true;
153+
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
154+
return result;
155+
}
156+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
157+
}
158+
159+
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
160+
{
161+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService))
162+
{
163+
return new System.ServiceModel.EndpointAddress("https://localhost/CoreWcfSamples/basicHttpTransportSecurity/CalculatorService/basicHttpTransportSecurity");
164+
}
165+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
166+
}
167+
168+
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
169+
{
170+
return CalculatorServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_ICalculatorService);
171+
}
172+
173+
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
174+
{
175+
return CalculatorServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_ICalculatorService);
176+
}
177+
178+
public enum EndpointConfiguration
179+
{
180+
181+
BasicHttpBinding_ICalculatorService,
182+
}
183+
}
184+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
namespace CoreWcf.Samples.TransportSecurity
5+
{
6+
//The service contract is defined using Connected Service "WCF Web Service", generated from the service by the dotnet svcutil tool.
7+
8+
//Client implementation code.
9+
class Client
10+
{
11+
static void Main()
12+
{
13+
// Create a client with given client endpoint configuration
14+
CalculatorServiceClient client = new CalculatorServiceClient();
15+
16+
// Call the Add service operation.
17+
double value1 = 100.00D;
18+
double value2 = 15.99D;
19+
double result = client.Add(value1, value2);
20+
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
21+
22+
// Call the Subtract service operation.
23+
value1 = 145.00D;
24+
value2 = 76.54D;
25+
result = client.Subtract(value1, value2);
26+
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
27+
28+
// Call the Multiply service operation.
29+
value1 = 9.00D;
30+
value2 = 81.25D;
31+
result = client.Multiply(value1, value2);
32+
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
33+
34+
// Call the Divide service operation.
35+
value1 = 22.00D;
36+
value2 = 7.00D;
37+
result = client.Divide(value1, value2);
38+
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
39+
40+
//Closing the client gracefully closes the connection and cleans up resources
41+
client.CloseAsync();
42+
43+
Console.WriteLine();
44+
Console.WriteLine("Press <ENTER> to terminate client.");
45+
Console.ReadLine();
46+
}
47+
}
48+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
namespace CoreWcf.Samples.TransportSecurity
5+
{
6+
// Service class which implements the service contract interface.
7+
public class CalculatorService : ICalculatorService
8+
{
9+
public double Add(double n1, double n2)
10+
{
11+
return n1 + n2;
12+
}
13+
14+
public double Subtract(double n1, double n2)
15+
{
16+
return n1 - n2;
17+
}
18+
19+
public double Multiply(double n1, double n2)
20+
{
21+
return n1 * n2;
22+
}
23+
24+
public double Divide(double n1, double n2)
25+
{
26+
return n1 / n2;
27+
}
28+
}
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
namespace CoreWcf.Samples.TransportSecurity
5+
{
6+
// Define a service contract.
7+
[ServiceContract]
8+
public interface ICalculatorService
9+
{
10+
[OperationContract]
11+
double Add(double n1, double n2);
12+
[OperationContract]
13+
double Subtract(double n1, double n2);
14+
[OperationContract]
15+
double Multiply(double n1, double n2);
16+
[OperationContract]
17+
double Divide(double n1, double n2);
18+
}
19+
}
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(CoreWCF.Channels.BasicHttpSecurityMode.Transport), "/CalculatorService/basicHttpTransportSecurity");
19+
20+
// Configure WSDL to be available
21+
var serviceMetadataBehavior = app.Services.GetRequiredService<ServiceMetadataBehavior>();
22+
serviceMetadataBehavior.HttpsGetEnabled = true;
23+
});
24+
25+
app.Run();

0 commit comments

Comments
 (0)