dotnet / dotnet/wcf

Factory pattern discussion & feedback

Open
#4,139 4 comments 0 reactions 1 assignee Claimed by @mconnew View on GitHub
customer assistance
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

The other day I was porting some code to .NET Core which consumes a WCF service one of our partners stood up. The System.ServiceModel library works great, but I was finding myself painted into a corner when it came to managing the ChannelFactory, ClientBase, and options reloading. Basically lots of code where it didn't belong newing up stuff and doing configuration. I'm a fan of how [HttpClientFactory](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests) manages HttpClients, so I took a stab at porting that pattern to WCF. End result is here: [Macross.ServiceModel.Extensions](https://www.nuget.org/packages/Macross.ServiceModel.Extensions/)

My thinking was: Just because it's a port from .NET Framework doesn't mean we can't use it in a .NET Core-ish way! Anyway, this issue is to gather some feedback from the experts.

Example:
```csharp
[ServiceContract]
public interface ILegacyProductProxy
{
[OperationContract]
Task GetStatusAsync();
}

public class ProductService : ILegacyProductProxy
{
private readonly ILogger _Logger;
private readonly SoapClient _SoapClient;

public ProductService(ILogger logger, SoapClient soapClient)
{
_Logger = logger ?? throw new ArgumentNullException(nameof(logger));
_SoapClient = soapClient ?? throw new ArgumentNullException(nameof(soapClient));
}

public Task GetStatusAsync() => _SoapClient.Channel.GetStatusAsync();
}

public void ConfigureServices(IServiceCollection services)
{
services.AddSoapClient(()
=> new ChannelFactory(
new BasicHttpBinding(),
new EndpointAddress("http://localhost/LegacyService/")));
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.