Skip to content

Commit

Permalink
Add WCF sample [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
CZEMacLeod committed Mar 13, 2022
1 parent 9e2e176 commit 13a2e5f
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 0 deletions.
17 changes: 17 additions & 0 deletions MSBuild.SDK.SystemWeb.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.SDK.SystemWeb.Templ
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "docs", "docs\docs.csproj", "{9E629342-F10C-4EA4-A578-016DD5713C1F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WCF", "WCF", "{DD85524D-6840-45D5-A450-1AAA8B1F2993}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WCF.Service.ClassLibrary", "samples\WCF\WCF.Service.ClassLibrary\WCF.Service.ClassLibrary.csproj", "{0272B7E9-0AA9-49C4-89EC-5223AFFFE3B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleWCFWebApplication", "samples\WCF\WCF.Service.WebApplication\ExampleWCFWebApplication.csproj", "{8EEC969D-F112-437D-8967-1FBB0C4624BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -58,13 +64,24 @@ Global
{750A2B35-A9BB-488B-972C-31FEAB17CF3A}.Release|Any CPU.Build.0 = Release|Any CPU
{9E629342-F10C-4EA4-A578-016DD5713C1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E629342-F10C-4EA4-A578-016DD5713C1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0272B7E9-0AA9-49C4-89EC-5223AFFFE3B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0272B7E9-0AA9-49C4-89EC-5223AFFFE3B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0272B7E9-0AA9-49C4-89EC-5223AFFFE3B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0272B7E9-0AA9-49C4-89EC-5223AFFFE3B8}.Release|Any CPU.Build.0 = Release|Any CPU
{8EEC969D-F112-437D-8967-1FBB0C4624BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EEC969D-F112-437D-8967-1FBB0C4624BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EEC969D-F112-437D-8967-1FBB0C4624BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EEC969D-F112-437D-8967-1FBB0C4624BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BA8C0E69-87E1-46F8-A871-F1CDD8760A75} = {4A37969E-D8DB-4AAA-A382-D6E733B6185B}
{53B1BADD-D5EF-4209-82EA-CB37525D07AF} = {4A37969E-D8DB-4AAA-A382-D6E733B6185B}
{DD85524D-6840-45D5-A450-1AAA8B1F2993} = {4A37969E-D8DB-4AAA-A382-D6E733B6185B}
{0272B7E9-0AA9-49C4-89EC-5223AFFFE3B8} = {DD85524D-6840-45D5-A450-1AAA8B1F2993}
{8EEC969D-F112-437D-8967-1FBB0C4624BE} = {DD85524D-6840-45D5-A450-1AAA8B1F2993}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E5FBE1CF-A73C-4BFD-BBA5-95488B7930D9}
Expand Down
44 changes: 44 additions & 0 deletions samples/WCF/WCF.Service.ClassLibrary/Service2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

namespace WCF.Service.ClassLibrary;

[ServiceContract]
public interface ICalculator2
{
[OperationContract]
[WebGet]
double Add(double n1, double n2);
[OperationContract]
[WebGet]
double Subtract(double n1, double n2);
[OperationContract]
[WebGet]
double Multiply(double n1, double n2);
[OperationContract]
[WebGet]
double Divide(double n1, double n2);
}

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CalculatorService2 : ICalculator2
{
public double Add(double n1, double n2)
{
return n1 + n2;
}
public double Subtract(double n1, double n2)
{
return n1 - n2;
}
public double Multiply(double n1, double n2)
{
return n1 * n2;
}
public double Divide(double n1, double n2)
{
return n1 / n2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.ServiceModel.Web.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="MSBuild.SDK.SystemWeb">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<MicrosoftNetCompilersToolset_Version>4.1.0</MicrosoftNetCompilersToolset_Version>
<LangVersion>10</LangVersion>
</PropertyGroup>
<PropertyGroup>
<Copyright>Copyright © 2022</Copyright>
</PropertyGroup>
<ItemGroup>
<None Include="Properties\launchSettings.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WCF.Service.ClassLibrary\WCF.Service.ClassLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ServiceModel" />
<Content Include="Global.asax" />
<Content Include="*.svc" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Runtime.InteropServices;

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5FBFD242-8B80-4E81-9D44-B147FA7E0A69")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:57506",
"sslPort": 44386
}
},
"profiles": {
"IIS Express Local Service": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"launchUrl": "http://localhost:57506/service.svc"
},
"IIS Express Class Library": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"launchUrl": "http://localhost:57506/service2/Add?n1=420&n2=0.69"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.ServiceModel;

namespace ExampleWCFWebApplication.Services;

[ServiceContract]
public interface ICalculator
{
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
double Subtract(double n1, double n2);
[OperationContract]
double Multiply(double n1, double n2);
[OperationContract]
double Divide(double n1, double n2);
}

public class CalculatorService : ICalculator
{
public double Add(double n1, double n2)
{
return n1 + n2;
}
public double Subtract(double n1, double n2)
{
return n1 - n2;
}
public double Multiply(double n1, double n2)
{
return n1 * n2;
}
public double Divide(double n1, double n2)
{
return n1 / n2;
}
}
30 changes: 30 additions & 0 deletions samples/WCF/WCF.Service.WebApplication/Web.Debug.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
31 changes: 31 additions & 0 deletions samples/WCF/WCF.Service.WebApplication/Web.Release.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
53 changes: 53 additions & 0 deletions samples/WCF/WCF.Service.WebApplication/Web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
</handlers>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

<services>
<service name="ExampleWCFWebApplication.Services.CalculatorService" behaviorConfiguration="CalculatorServiceBehaviors">

<!-- This endpoint is exposed at the base address provided by host: http://localhost/service.svc -->
<endpoint address=""
binding="wsHttpBinding"
contract="ExampleWCFWebApplication.Services.ICalculator" />

<!-- The mex endpoint is exposed at http://localhost/service.svc/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>

<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehaviors">
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
16 changes: 16 additions & 0 deletions samples/WCF/WCF.Service.WebApplication/global.asax
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.ServiceModel.Activation" %>
<%@ Import Namespace="System.ServiceModel.Web " %>

<script RunAt="server">
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
private void RegisterRoutes(RouteCollection routes)
{
routes.Add(new ServiceRoute("service2", new WebServiceHostFactory(), typeof(WCF.Service.ClassLibrary.CalculatorService2)));
}
</script>
1 change: 1 addition & 0 deletions samples/WCF/WCF.Service.WebApplication/service.svc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ServiceHost language="c#" Debug="true" Service="ExampleWCFWebApplication.Services.CalculatorService"%>

0 comments on commit 13a2e5f

Please sign in to comment.