Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Source/Csla.Channels.Wcf/Client/IWcfPortal.cs
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);
Comment thread
b-higginbotham marked this conversation as resolved.
}
}
71 changes: 71 additions & 0 deletions Source/Csla.Channels.Wcf/Client/WcfClientExtensions.cs
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);
}
}
47 changes: 47 additions & 0 deletions Source/Csla.Channels.Wcf/Client/WcfPortalClient.cs
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);
}
}
91 changes: 91 additions & 0 deletions Source/Csla.Channels.Wcf/Client/WcfProxy.cs
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));

Comment thread
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;
}
}
}
29 changes: 29 additions & 0 deletions Source/Csla.Channels.Wcf/Client/WcfProxyOptions.cs
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";
}
}
37 changes: 37 additions & 0 deletions Source/Csla.Channels.Wcf/Csla.Channels.Wcf.csproj
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(&quot;net4&quot;))">
<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" />
Comment thread
b-higginbotham marked this conversation as resolved.
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions Source/Csla.Channels.Wcf/Server/IWcfPortalServer.cs
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")]
Comment thread
b-higginbotham marked this conversation as resolved.
Task<WcfResponse> InvokeAsync(WcfRequest request);
}
}
Loading
Loading