Skip to content

Commit 2cfd3ef

Browse files
authored
Add BasicHttpBinding Sample - IIS Hosted (#24)
* Add BasicHttpBinding Sample - IIS Hosted
1 parent c7e40c5 commit 2cfd3ef

File tree

14 files changed

+473
-0
lines changed

14 files changed

+473
-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+
"http://localhost/CoreWcfSamples/CalculatorService?singleWsdl"
5+
],
6+
"collectionTypes": [
7+
"System.Array",
8+
"System.Collections.Generic.Dictionary`2"
9+
],
10+
"namespaceMappings": [
11+
"*, CoreWcf.Samples.Http"
12+
],
13+
"sync": true,
14+
"targetFramework": "net6.0",
15+
"typeReuseMode": "All"
16+
}
17+
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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.Http
11+
{
12+
13+
14+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3")]
15+
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="CoreWcf.Samples.Http.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.Http.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.Http.ICalculatorService>, CoreWcf.Samples.Http.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+
return result;
154+
}
155+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
156+
}
157+
158+
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
159+
{
160+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ICalculatorService))
161+
{
162+
return new System.ServiceModel.EndpointAddress("http://localhost/CoreWcfSamples/CalculatorService/CalculatorService/basicHttp");
163+
}
164+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
165+
}
166+
167+
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
168+
{
169+
return CalculatorServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_ICalculatorService);
170+
}
171+
172+
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
173+
{
174+
return CalculatorServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_ICalculatorService);
175+
}
176+
177+
public enum EndpointConfiguration
178+
{
179+
180+
BasicHttpBinding_ICalculatorService,
181+
}
182+
}
183+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+

2+
namespace CoreWcf.Samples.Http
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+
class Client
8+
{
9+
static void Main()
10+
{
11+
// Create a client with given client endpoint configuration
12+
CalculatorServiceClient client = new CalculatorServiceClient();
13+
14+
// Call the Add service operation.
15+
double value1 = 100.00D;
16+
double value2 = 15.99D;
17+
double result = client.Add(value1, value2);
18+
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
19+
20+
// Call the Subtract service operation.
21+
value1 = 145.00D;
22+
value2 = 76.54D;
23+
result = client.Subtract(value1, value2);
24+
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
25+
26+
// Call the Multiply service operation.
27+
value1 = 9.00D;
28+
value2 = 81.25D;
29+
result = client.Multiply(value1, value2);
30+
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
31+
32+
// Call the Divide service operation.
33+
value1 = 22.00D;
34+
value2 = 7.00D;
35+
result = client.Divide(value1, value2);
36+
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
37+
38+
//Closing the client gracefully closes the connection and cleans up resources
39+
client.CloseAsync();
40+
41+
Console.WriteLine();
42+
Console.WriteLine("Press <ENTER> to terminate client.");
43+
Console.ReadLine();
44+
}
45+
}
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace CoreWcf.Samples.Http
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+

2+
using CoreWCF;
3+
4+
namespace CoreWcf.Samples.Http
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.Extensions.Hosting;
5+
6+
namespace CoreWcf.Samples.Http
7+
{
8+
public class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
IWebHost host = CreateWebHostBuilder(args).Build();
13+
host.Run();
14+
}
15+
16+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17+
WebHost.CreateDefaultBuilder(args)
18+
.UseStartup<BasicHttpBindingStartup>();
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
4+
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
5+
-->
6+
<Project>
7+
<PropertyGroup>
8+
<WebPublishMethod>MSDeploy</WebPublishMethod>
9+
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
10+
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
11+
<LastUsedPlatform>Any CPU</LastUsedPlatform>
12+
<SiteUrlToLaunchAfterPublish>http://localhost/CoreWcfSamples/CalculatorService</SiteUrlToLaunchAfterPublish>
13+
<ExcludeApp_Data>false</ExcludeApp_Data>
14+
<ProjectGuid>bf126326-3393-407c-b24a-8fccc388be27</ProjectGuid>
15+
<SelfContained>false</SelfContained>
16+
<MSDeployServiceURL>localhost</MSDeployServiceURL>
17+
<DeployIisAppPath>Default Web Site/CoreWcfSamples/CalculatorService</DeployIisAppPath>
18+
<RemoteSitePhysicalPath />
19+
<SkipExtraFilesOnServer>true</SkipExtraFilesOnServer>
20+
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
21+
<EnableMSDeployBackup>false</EnableMSDeployBackup>
22+
<EnableMsDeployAppOffline>true</EnableMsDeployAppOffline>
23+
<UserName />
24+
<_SavePWD>false</_SavePWD>
25+
<TargetFramework>net6.0</TargetFramework>
26+
</PropertyGroup>
27+
</Project>

0 commit comments

Comments
 (0)