Skip to content

Commit

Permalink
added ServiceModel service support
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomorgado committed Jul 15, 2021
1 parent 13e1645 commit 7a801a5
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 12 deletions.
17 changes: 16 additions & 1 deletion Microsoft.Extensions.AspNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".info", ".info", "{BE18BA32
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Extensions.Configuration.ConfigurationManager", "src\Microsoft.Extensions.Configuration.ConfigurationManager\Microsoft.Extensions.Configuration.ConfigurationManager.csproj", "{EB4BBFE9-108E-48C4-AF64-2806CD96E06D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Configuration.ConfigurationManager", "src\Microsoft.Extensions.Configuration.ConfigurationManager\Microsoft.Extensions.Configuration.ConfigurationManager.csproj", "{EB4BBFE9-108E-48C4-AF64-2806CD96E06D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Configuration.ConfigurationManager.Tests", "tests\Microsoft.Extensions.Configuration.ConfigurationManager.Tests\Microsoft.Extensions.Configuration.ConfigurationManager.Tests.csproj", "{D6BB544A-7A32-4C2B-A5BA-3DC6A5C0CA5E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Extensions.ServiceModel", "src\Microsoft.Extensions.ServiceModel\Microsoft.Extensions.ServiceModel.csproj", "{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -198,6 +200,18 @@ Global
{D6BB544A-7A32-4C2B-A5BA-3DC6A5C0CA5E}.Release|x64.Build.0 = Release|Any CPU
{D6BB544A-7A32-4C2B-A5BA-3DC6A5C0CA5E}.Release|x86.ActiveCfg = Release|Any CPU
{D6BB544A-7A32-4C2B-A5BA-3DC6A5C0CA5E}.Release|x86.Build.0 = Release|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Debug|x64.ActiveCfg = Debug|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Debug|x64.Build.0 = Debug|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Debug|x86.ActiveCfg = Debug|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Debug|x86.Build.0 = Debug|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Release|Any CPU.Build.0 = Release|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Release|x64.ActiveCfg = Release|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Release|x64.Build.0 = Release|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Release|x86.ActiveCfg = Release|Any CPU
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -215,6 +229,7 @@ Global
{F29821A2-9312-4ABF-AC2C-D06D3AF67919} = {A4274275-5F57-4EC3-9651-AD4BCFB0E488}
{EB4BBFE9-108E-48C4-AF64-2806CD96E06D} = {2355A742-ABD4-402A-8040-A46B7D88BAB5}
{D6BB544A-7A32-4C2B-A5BA-3DC6A5C0CA5E} = {85C121D2-EBA5-4580-A375-4383371885A0}
{DDF80027-4AFA-45F2-BE32-2EDA81B620FD} = {2355A742-ABD4-402A-8040-A46B7D88BAB5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {20512F05-6FBC-47B7-BBE8-949744341E3D}
Expand Down
18 changes: 15 additions & 3 deletions demo/SampleWebApplication/SampleWebApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TypeScriptToolsVersion>4.3</TypeScriptToolsVersion>
<WcfConfigValidationEnabled>True</WcfConfigValidationEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -214,6 +215,7 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath>
<Private>True</Private>
Expand All @@ -229,6 +231,7 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Text.Encodings.Web, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Text.Encodings.Web.5.0.1\lib\net461\System.Text.Encodings.Web.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -317,7 +320,8 @@
<Content Include="Content\bootstrap-reboot.css.map" />
<Content Include="Content\bootstrap-grid.min.css.map" />
<Content Include="Content\bootstrap-grid.css.map" />
<Content Include="WebServices\Feed.ashx" />
<Content Include="ServiceModel\Feed.svc" />
<Content Include="WebHandlers\Feed.ashx" />
<None Include="Scripts\jquery.validate-vsdoc.js" />
<Content Include="Scripts\jquery.validate.js" />
<Content Include="Scripts\jquery.validate.min.js" />
Expand Down Expand Up @@ -356,7 +360,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\Startup.cs" />
<Compile Include="WebServices\Feed.ashx.cs">
<Compile Include="ServiceModel\Feed.svc.cs">
<DependentUpon>Feed.svc</DependentUpon>
</Compile>
<Compile Include="ServiceModel\IFeed.cs" />
<Compile Include="WebHandlers\Feed.ashx.cs">
<DependentUpon>Feed.ashx</DependentUpon>
</Compile>
<Compile Include="Options\ApplicationOptions.cs" />
Expand Down Expand Up @@ -439,6 +447,10 @@
<Project>{eb4bbfe9-108e-48c4-af64-2806cd96e06d}</Project>
<Name>Microsoft.Extensions.Configuration.ConfigurationManager</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.Extensions.ServiceModel\Microsoft.Extensions.ServiceModel.csproj">
<Project>{ddf80027-4afa-45f2-be32-2eda81b620fd}</Project>
<Name>Microsoft.Extensions.ServiceModel</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand All @@ -456,7 +468,7 @@
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>1267</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>https://localhost:44373/</IISUrl>
<IISUrl>https://localhost:44383/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand Down
1 change: 1 addition & 0 deletions demo/SampleWebApplication/ServiceModel/Feed.svc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ ServiceHost Language="C#" Debug="true" Service="SampleWebApplication.ServiceModel.Feed" CodeBehind="Feed.svc.cs" %>
31 changes: 31 additions & 0 deletions demo/SampleWebApplication/ServiceModel/Feed.svc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.ServiceModel;
using System.ServiceModel.Syndication;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.ServiceModel.DependencyInjection;
using SampleWebApplication.Options;
using SampleWebApplication.Services;

namespace SampleWebApplication.ServiceModel
{
[SystemWebHostServiceBehavior()]
public class Feed : IFeed
{
private readonly ISyndicationClient syndicationClient;
private readonly FeedOptions options;

public Feed(ISyndicationClient syndicationClient, IOptions<FeedOptions> options)
{
this.syndicationClient = syndicationClient ?? throw new ArgumentNullException(nameof(syndicationClient));
this.options = options?.Value ?? throw new ArgumentNullException(nameof(options));
}

public async Task<string> GetFeedAsync()
{
var feed = await syndicationClient.GetSyndicationFeedAsync(options.Uri);

return feed.Title.Text;
}
}
}
14 changes: 14 additions & 0 deletions demo/SampleWebApplication/ServiceModel/IFeed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ServiceModel;
using System.ServiceModel.Syndication;
using System.Threading.Tasks;

namespace SampleWebApplication.ServiceModel
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IFeed" in both code and config file together.
[ServiceContract]
public interface IFeed
{
[OperationContract(Action = "GetFeed")]
Task<string> GetFeedAsync();
}
}
2 changes: 1 addition & 1 deletion demo/SampleWebApplication/Site.Master
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<li><a runat="server" href="~/Home/Index">MVC</a></li>
<li><a runat="server" href="~/Default.aspx">Web Forms</a></li>
<li><a runat="server" href="~/api/feed" target="_blank">Web API</a></li>
<li><a runat="server" href="~/WebServices/Feed.ashx" target="_blank">Web Handler</a></li>
<li><a runat="server" href="~/WebHandlers/Feed.ashx" target="_blank">Web Handler</a></li>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion demo/SampleWebApplication/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<li>@Html.ActionLink("MVC", "Index", "Home")</li>
<li><a href="~/Default.aspx">Web Forms</a></li>
<li><a runat="server" href="~/api/feed" target="_blank">Web API</a></li>
<li><a runat="server" href="~/WebServices/Feed.ashx" target="_blank">Web Handler</a></li>
<li><a runat="server" href="~/WebHandlers/Feed.ashx" target="_blank">Web Handler</a></li>
</ul>
</div>
</div>
Expand Down
20 changes: 18 additions & 2 deletions demo/SampleWebApplication/Web.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?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
Expand Down Expand Up @@ -38,7 +38,7 @@
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<modules>
<modules runAllManagedModulesForAllRequests="true">
<add name="SystemWebHostModule" type="Microsoft.AspNet.Hosting.SystemWeb.SystemWebHostModule, Microsoft.AspNet.Hosting.SystemWeb"/>
</modules>
</system.webServer>
Expand Down Expand Up @@ -122,4 +122,20 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%@ WebHandler Language="C#" CodeBehind="Feed.ashx.cs" Class="SampleWebApplication.WebServices.FeedHandler" %>
<%@ WebHandler Language="C#" CodeBehind="Feed.ashx.cs" Class="SampleWebApplication.WebHandlers.FeedHandler" %>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using SampleWebApplication.Options;
using SampleWebApplication.Services;

namespace SampleWebApplication.WebServices
namespace SampleWebApplication.WebHandlers
{
/// <summary>
/// Summary description for Feed
Expand All @@ -20,12 +20,12 @@ public class FeedHandler : HttpTaskAsyncHandler
public FeedHandler(ISyndicationClient syndicationClient, IOptions<FeedOptions> feedOptions)
{
this.syndicationClient = syndicationClient;
this.options = feedOptions.Value;
options = feedOptions.Value;
}

public override async Task ProcessRequestAsync(HttpContext context)
{
var feed = await this.syndicationClient.GetSyndicationFeedAsync(this.options.Uri);
var feed = await syndicationClient.GetSyndicationFeedAsync(options.Uri);

var response = new XElement("Feed",
new XElement("Title", feed.Title.Text),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.Web;

namespace Microsoft.Extensions.ServiceModel.DependencyInjection
{
internal sealed class SystemWebHostDependencyInjectionInstanceProvider : IInstanceProvider
{
public static readonly SystemWebHostDependencyInjectionInstanceProvider Shared = new SystemWebHostDependencyInjectionInstanceProvider();

public object GetInstance(InstanceContext instanceContext)
{
return GetInstance(instanceContext, null);
}

public object GetInstance(InstanceContext instanceContext, Message message)
{
return HttpRuntime.WebObjectActivator.GetService(instanceContext.Host.Description.ServiceType);
}

public void ReleaseInstance(InstanceContext instanceContext, object instance)
{
}
}
}
Loading

0 comments on commit 7a801a5

Please sign in to comment.