-
-
Notifications
You must be signed in to change notification settings - Fork 401
Implement WCF Data Portal Channel #4851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
394ecef
Added WCF Data Portal Channel
82ec6a0
Merge branch 'MarimerLLC:main' into wcf-portal
b-higginbotham b85bf0d
Fix a typo in XML comment
b-higginbotham 980b31b
Fix typo in XML comment
b-higginbotham 74fa936
Fix typos in readme.md
7030477
Merge branch 'wcf-portal' of https://github.com/b-higginbotham/csla i…
24259d1
remove Console.WriteLine that was used for debugging
d975371
Add WCF portal integration tests
1ab43d8
Replace ChannelFactory with ClientBase.
f28e27d
Revert VisualStudioVersion change in csla.test.sln
b-higginbotham 03b0a94
Fix typos in XML comments
be5c683
Merge branch 'wcf-portal' of https://github.com/b-higginbotham/csla i…
71964e3
Fix client not being closed after sync call
69c9d90
Add missing file header
942edea
Add support for data portal routing
7628b76
Remove test that cannot fail
e9134f9
Merge branch 'main' into wcf-portal
rockfordlhotka 1973c69
Remove unnecessary wrapping of return value
510737c
Merge branch 'wcf-portal' of https://github.com/b-higginbotham/csla i…
4c92ea5
Remove WCF sample that isn't ready yet
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="IWcfPortal.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>Provides consistent context information between the client</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using System.ServiceModel; | ||
|
|
||
| namespace Csla.Channels.Wcf.Client | ||
| { | ||
| /// <summary> | ||
| /// Represents the WCF service contract that is used for communication between the data portal client and server. | ||
| /// </summary> | ||
| [ServiceContract] | ||
| public interface IWcfPortal | ||
| { | ||
| /// <summary> | ||
| /// Asynchronously invokes an operation on the remote data portal. | ||
| /// </summary> | ||
| /// <param name="request"> | ||
| /// The request that contains the name and parameters necessary to invoke the data portal operation. | ||
| /// </param> | ||
| /// <returns> | ||
| /// A task containing the response from the remote data portal. | ||
| /// </returns> | ||
| [OperationContract(Action = "https://cslanet.com/IwcfPortal/Invoke", ReplyAction = "https://cslanet.com/IwcfPortal/InvokeResponse")] | ||
| Task<WcfResponse> InvokeAsync(WcfRequest request); | ||
|
|
||
| /// <summary> | ||
| /// Synchronously invokes an operation on the remote data portal. | ||
| /// </summary> | ||
| /// <param name="request"> | ||
| /// The request that contains the name and parameters necessary to invoke the data portal operation. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The response from the remote data portal. | ||
| /// </returns> | ||
| [OperationContract(Action = "https://cslanet.com/IwcfPortal/Invoke", ReplyAction = "https://cslanet.com/IwcfPortal/InvokeResponse")] | ||
| WcfResponse Invoke(WcfRequest request); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="WcfClientExtensions.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>Provides consistent context information between the client</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using Csla.Configuration; | ||
| using Csla.DataPortalClient; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Csla.Channels.Wcf.Client | ||
| { | ||
| /// <summary> | ||
| /// Provides extension methods that can be used to configure the client side data portal to use the WCF channel. | ||
| /// </summary> | ||
| public static class WcfClientExtensions | ||
| { | ||
| /// <summary> | ||
| /// Configures the client side data portal to use the WCF channel. | ||
| /// </summary> | ||
| /// <param name="config"> | ||
| /// The client side data portal options that the WCF configuration will be applied to. | ||
| /// </param> | ||
| /// <param name="setOptions"> | ||
| /// An optional action that will be invoked to set options for the <see cref="WcfProxy"/>. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The <paramref name="config"/> with the WCF configuration applied. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// <paramref name="config"/> is <see langword="null"/>. | ||
| /// </exception> | ||
| public static DataPortalClientOptions UseWcfProxy(this DataPortalClientOptions config, Action<WcfProxyOptions>? setOptions) | ||
| { | ||
| if (config is null) | ||
| throw new ArgumentNullException(nameof(config)); | ||
|
|
||
| var proxyOptions = new WcfProxyOptions(); | ||
|
|
||
| setOptions?.Invoke(proxyOptions); | ||
|
|
||
| config.Services.AddSingleton(_ => proxyOptions); | ||
| config.Services.AddTransient<IDataPortalProxy>(provider => | ||
| { | ||
| var applicationContext = provider.GetRequiredService<ApplicationContext>(); | ||
| var options = provider.GetRequiredService<WcfProxyOptions>(); | ||
| var dataPortalOptions = provider.GetRequiredService<DataPortalOptions>(); | ||
| var wcfProxy = new WcfProxy(applicationContext, options, dataPortalOptions); | ||
| return wcfProxy; | ||
| }); | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Configures the client side data portal to use the WCF channel. | ||
| /// </summary> | ||
| /// <param name="config"> | ||
| /// The client side data portal options that the WCF configuration will be applied to. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The <paramref name="config"/> with the WCF configuration applied. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// <paramref name="config"/> is <see langword="null"/>. | ||
| /// </exception> | ||
| public static DataPortalClientOptions UseWcfProxy(this DataPortalClientOptions config) => config.UseWcfProxy(null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="WcfPortalClient.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>Provides consistent context information between the client</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using System.ServiceModel; | ||
| using System.ServiceModel.Channels; | ||
|
|
||
| namespace Csla.Channels.Wcf.Client | ||
| { | ||
| /// <summary> | ||
| /// Represents a WCF client that is used by the <see cref="WcfProxy"/> to communicate with a remote data portal. | ||
| /// </summary> | ||
| /// <param name="binding"> | ||
| /// The WCF binding that is used to communicate with the remote WCF data portal service. | ||
| /// </param> | ||
| /// <param name="address"> | ||
| /// The endpoint address that is used to communicate with the remote WCF data portal service. | ||
| /// </param> | ||
| internal class WcfPortalClient(Binding binding, EndpointAddress address) : ClientBase<IWcfPortal>(binding, address), IWcfPortal | ||
| { | ||
| /// <summary> | ||
| /// Asynchronously invokes an operation on the remote data portal. | ||
| /// </summary> | ||
| /// <param name="request"> | ||
| /// The request that contains the name and parameters necessary to invoke the data portal operation. | ||
| /// </param> | ||
| /// <returns> | ||
| /// A task containing the response from the remote data portal. | ||
| /// </returns> | ||
| public Task<WcfResponse> InvokeAsync(WcfRequest request) => Channel.InvokeAsync(request); | ||
|
|
||
| /// <summary> | ||
| /// Synchronously invokes an operation on the remote data portal. | ||
| /// </summary> | ||
| /// <param name="request"> | ||
| /// The request that contains the name and parameters necessary to invoke the data portal operation. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The response from the remote data portal. | ||
| /// </returns> | ||
| public WcfResponse Invoke(WcfRequest request) => Channel.Invoke(request); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="WcfProxy.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>Provides consistent context information between the client</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using System.ServiceModel; | ||
| using Csla.Configuration; | ||
| using Csla.DataPortalClient; | ||
|
|
||
| namespace Csla.Channels.Wcf.Client | ||
| { | ||
| /// <summary> | ||
| /// Represents a <see cref="DataPortalProxy"/> that communicates with a remote data portal using WCF. | ||
| /// </summary> | ||
| /// <param name="applicationContext"> | ||
| /// The client side context for the data portal. | ||
| /// </param> | ||
| /// <param name="wcfProxyOptions"> | ||
| /// The options that are used to configure the data portal proxy. | ||
| /// </param> | ||
| /// <param name="dataPortalOptions"> | ||
| /// The options that are used to configure the client side data portal. | ||
| /// </param> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// <paramref name="wcfProxyOptions"/> is <see langword="null"/>. | ||
| /// </exception> | ||
| public class WcfProxy(ApplicationContext applicationContext, WcfProxyOptions wcfProxyOptions, DataPortalOptions dataPortalOptions) : DataPortalProxy(applicationContext) | ||
| { | ||
| protected WcfProxyOptions _options = wcfProxyOptions ?? throw new ArgumentNullException(nameof(wcfProxyOptions)); | ||
| protected string? _versionRoutingTag = dataPortalOptions.VersionRoutingTag; | ||
|
|
||
| /// <summary> | ||
| /// Gets the URL address for the data portal server used by this proxy instance. | ||
| /// </summary> | ||
| public override string DataPortalUrl => _options.DataPortalUrl; | ||
|
|
||
| protected override async Task<byte[]> CallDataPortalServer(byte[] serialized, string operation, string? routingToken, bool isSync) | ||
| { | ||
| var client = new WcfPortalClient(_options.Binding, new EndpointAddress(_options.DataPortalUrl)); | ||
|
|
||
|
b-higginbotham marked this conversation as resolved.
|
||
| var wcfRequest = new WcfRequest | ||
| { | ||
| Operation = CreateOperationTag(operation, _versionRoutingTag, routingToken), | ||
| Body = serialized | ||
| }; | ||
|
|
||
| try | ||
| { | ||
| var response = isSync ? client.Invoke(wcfRequest) : await client.InvokeAsync(wcfRequest); | ||
|
|
||
| client.Close(); | ||
|
|
||
| return response.Body; | ||
| } | ||
| catch (Exception) | ||
| { | ||
| client.Abort(); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| internal async Task<WcfResponse> RouteMessage(WcfRequest request) | ||
| { | ||
| var client = new WcfPortalClient(_options.Binding, new EndpointAddress(_options.DataPortalUrl)); | ||
|
|
||
| try | ||
| { | ||
| var response = await client.InvokeAsync(request); | ||
|
|
||
| client.Close(); | ||
|
|
||
| return response; | ||
| } | ||
| catch (Exception) | ||
| { | ||
| client.Abort(); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| private string CreateOperationTag(string operation, string? versionToken, string? routingToken) | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(versionToken) || !string.IsNullOrWhiteSpace(routingToken)) | ||
| return $"{operation}/{routingToken}-{versionToken}"; | ||
| return operation; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="WcfProxyOptions.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>Provides consistent context information between the client</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using System.ServiceModel; | ||
| using System.ServiceModel.Channels; | ||
|
|
||
| namespace Csla.Channels.Wcf.Client | ||
| { | ||
| /// <summary> | ||
| /// Represents options that are used to configure a WCF data portal proxy. | ||
| /// </summary> | ||
| public class WcfProxyOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the WCF binding that should be used to communicate with the remote WCF data portal service. | ||
| /// </summary> | ||
| public Binding Binding { get; set; } = new BasicHttpBinding(); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the URL that should be used to communicate with the remote WCF data portal service. | ||
| /// </summary> | ||
| public string DataPortalUrl { get; set; } = "http://localhost"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net462;net472;net48;net8.0;net9.0;net10.0</TargetFrameworks> | ||
| <LangVersion>Latest</LangVersion> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Csla\Csla.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="$(TargetFramework.StartsWith("net4"))"> | ||
| <Reference Include="System.ServiceModel" /> | ||
| <Reference Include="System.ServiceModel.Activation" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- CoreWCF libraries are only needed for modern .net targets. --> | ||
| <ItemGroup Condition="'$(TargetFramework)'=='net8.0' or '$(TargetFramework)'=='net9.0' or '$(TargetFramework)'=='net10.0'"> | ||
| <PackageReference Include="CoreWCF.Http" Version="1.8.0" /> | ||
| <PackageReference Include="CoreWCF.Primitives" Version="1.8.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- The supported target frameworks for the client side System.ServiceModel packages are not compatible between | ||
| versions 8.x and 10.x so they must be included under separate conditions. There is no 9.x version. --> | ||
| <ItemGroup Condition="'$(TargetFramework)'=='net8.0' or '$(TargetFramework)'=='net9.0'"> | ||
| <PackageReference Include="System.ServiceModel.Primitives" Version="8.1.2" /> | ||
| <PackageReference Include="System.ServiceModel.Http" Version="8.1.2" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'$(TargetFramework)'=='net10.0'"> | ||
| <PackageReference Include="System.ServiceModel.Primitives" Version="10.0.652802" /> | ||
| <PackageReference Include="System.ServiceModel.Http" Version="10.0.652802" /> | ||
|
b-higginbotham marked this conversation as resolved.
|
||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="IWcfPortalServer.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>Provides consistent context information between the client</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| #if NETFRAMEWORK | ||
| using System.ServiceModel; | ||
| #else | ||
| using CoreWCF; | ||
| #endif | ||
|
|
||
| namespace Csla.Channels.Wcf.Server | ||
| { | ||
| /// <summary> | ||
| /// Represents the WCF service contract that is used for communication between the data portal client and server. | ||
| /// </summary> | ||
| [ServiceContract] | ||
| public interface IWcfPortalServer | ||
| { | ||
| /// <summary> | ||
| /// Asynchronously invokes an operation on the remote data portal. | ||
| /// </summary> | ||
| /// <param name="request"> | ||
| /// The request that contains the name and parameters necessary to invoke the data portal operation. | ||
| /// </param> | ||
| /// <returns> | ||
| /// As task containing the response from the remote data portal. | ||
| /// </returns> | ||
| [OperationContract(Action = "https://cslanet.com/IwcfPortal/Invoke", ReplyAction = "https://cslanet.com/IwcfPortal/InvokeResponse")] | ||
|
b-higginbotham marked this conversation as resolved.
|
||
| Task<WcfResponse> InvokeAsync(WcfRequest request); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.