Giter Club home page Giter Club logo

netcore-wcf-service-proxy's Introduction

Why didn't I just use the existing connector?

This small project is my solution to a problem I came across when trying to access multiple WCF-services from a new ASP.NET Core project and could not get the official WCF-extension to properly create the interfaces.

Most of the examples found by simple googling came up with simple connector implementations. These did not showcase the actual problem and were lacking in situations where multiple connections are needed. The aim here is to create a generic, yet simple, way to handle such a situation.

What else is this solution good for?

The connected service reference is tied to one endpoint and to my knowledge the endpoint cannot be changed on the fly. Most web applications have multiple environments where they are run, so naturally the endpoints of WCF services will also change depending on the use case, ex. Production / Development implementations.

This Wcf proxy approach makes it possible to configure the endpoint in a configuration file and then configure the client itself to connect to this url, instead of using multiple separate connected service references.

Problem description

The first step in trying to enable WCF-services is to use the official Visual Studio extension found here:

https://blogs.msdn.microsoft.com/webdev/2016/06/26/wcf-connected-service-for-net-core-1-0-0-and-asp-net-core-1-0-0-is-now-available/

The WCF Connected service for .NET Core 3.1 should fit to most use cases, but the library is not compatible with more complex (or incorrectly configured) services. You might face an error similar to the following, in such a case, the best option is to connect programmatically to the service via a proxy class library. This repository shows one way to implement this approach.

Scaffolding Code …
Error:Error: No endpoints compatible with .Net Core apps were found.
An error occurred in the tool.

Failed to generate service reference. 

Solution

  1. Services are implemented in WcfServices
  2. WcfProxy project uses service references to create service contracts
  3. Wrapper classes in WcfProxy-project mask the actual services implementations and instad call them through the Proxy-class.
  4. Wrapper maps the Dtos to separate model classes
  5. ASP.NET Core injects the wrappers where they are used

The Wcf services are completely isolated from the ASP.NET implementation and no references are needed to WcfServices-project.

Running the solution

git clone https://github.com/jolmari/netcore-wcf-service-proxy.git
  1. Download the .NET Core 3.1 SDK & Runtime
  2. Open the solution Visual Studio 2019
  3. Build solution
  4. Open the NetCoreWebApp project, open context menu on references and restore packages
  5. Run the solution (Ctrl+F5/F5)

Alt text

This project includes:

  • Multiple WCF services

    • Simple examples of WCF services that are connected to by the proxy-class via message contracts.
    • IoC using built-in ASP.NET Core Dependency Injection.
  • WCF-proxy implementation

    • A class library project that wraps the actual service contracts with proxy implementations
  • ASP.NET Core client that calls is used to demonstrate the use cases

Troubleshooting

  1. The services don't start:
  • Solution Explorer -> Solution -> Properties -> Startup Project. Start WcfServices & NetCoreWebApp.

netcore-wcf-service-proxy's People

Contributors

crnd avatar jolmari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

netcore-wcf-service-proxy's Issues

Multiple Wcf Endpoints

The solution needs multiple WCF endpoints to truly show an example of a flexible and generic proxy implementation. The proxy itself needs to evolve also to accomodate this change.

Inversion of Control for dependency handling

Should replace the concrete object initialization logic in all of the projects with some sort of Dependency Injection pattern. Most likely the ASP.NET core built-in IoC is enough.

Config files

When authentication and endpoint URL based client creation is implemented, should store the necessary data in environment based config files.

Why Creating new WcfProxy in constructor?

Here i have 2 concerns.

  1. Why we are creating instances using new? Can we register it by dependency injection and inject the IWcfProxy in the constructor.
  private readonly IWcfProxy<IPersonService> clientProxy;

        public PersonServiceWrapper(string endpointUrl)
        {
            clientProxy = new WcfProxy<IPersonServiceChannel>(endpointUrl);
        }
public CountryServiceWrapper(IWcfProxy<ICountryServiceChannel> proxy)
        {
            clientProxy = proxy;
        }
        
 services.AddScoped<ICountryServiceWrapper>(provider => new CountryServiceWrapper(endpointsConfig.CountryService));
            services.AddScoped<IPersonServiceWrapper>(provider => new PersonServiceWrapper(endpointsConfig.PersonService));

  1. Another question is can we use the singleton registration for the WcfProxy class?
services.AddSingleton<IWcfProxy<ICarrierOperationsService>>(service =>
               new WcfProxy<ICarrierOperationsServiceChannel>(service
                   .GetRequiredService<IOptions<ServiceEndpointConfiguration>>().Value.CarrierOperationsService));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.