dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

Distributed design with AspNetCore #1345

Closed andreasandreou closed 6 years ago

andreasandreou commented 8 years ago

Hi,

In the company I work for we are starting a new project and are excited to use the latest and greatest from AspNetCore. However we have a dilemma I would appreciate your feedback on.

Initial approach was to go with MVC 5 on web server and WCF on the application server. Although this is a proven and well working architecture since we do want to use AspNetCore and MVC 6 we quickly discovered that using WCF on the application server would be a challenge since WCF implementation is not supported in AspNetCore.

We examined our options and limited them into three scenarios:

  1. Write the interfaces and proxies for WCF in AspNetCore and reference them 'normally' in our AspNetCore projects and as NuGet packages in WCF projects. The limitation being that every time we had to change the interfaces or proxies we would have to manually update the references.
  2. Use svcutil.exe to generate the mappings but again that would mean duplication of code and some manual job every time the service signature changes.
  3. Use something else as 'communication protocol' between web and app server. Here is where we need your valuable help :)

So.. long story short :) What is the suggested way for this kind of architecture?

Thank you in advance for your comments

MaximRouiller commented 8 years ago

Maybe use ASP.NET WebAPI, use swashbuckle to generate a Swagger file.

Then use something like NSwag to generate the code for your swagger file. I think NSwag can also generate your swagger file.

Here's the fun part. Controllers in MVC 5/Web API 2.2 are relatively easy to port to MVC 6/MVC Core 1.0. Yes, you'll need to change namespaces and the whole pipeline will be different but at least your controller code is almost copy/paste.

andreasandreou commented 8 years ago

Thanks for reply @MaximRouiller

We are working on fresh ground so we do need to worry about porting anything.

So from what I understand, your suggestion going forward, is to use WebAPI instead of WCF?

MaximRouiller commented 8 years ago

Yes sir.

Swagger is very fun in that you can go many ways to get the same result.

Scenario 1: Web API, no swagger file

As mentioned before, NSwag or Swashbuckle can help you generate a swagger file from existing code. This will generate a definition of your API.

Scenario 2: Swagger file, no web api

Think about 2 companies/team working together to integrate/build an API at the same time.

One swagger file. One company/team build the API while keeping the swagger file up to date. The other build the client basing themselves on the actual swagger file to ensure that their API uses yours properly.

Scenario 3: Swagger file, no clients

Now let's say that a company/team provides you a swagger file to consume their service. You don't want to write this boilerplate by hand. You want it auto-generated as much as possible.

Check their website for a list of tools : http://swagger.io/open-source-integrations/

andreasandreou commented 8 years ago

Thanks again @MaximRouiller

any other ideas regarding WCF vs WebAPI?

Is it safe to assume WebAPI is the future (even for web server to application server communication)?

MaximRouiller commented 8 years ago

WCF is hard to interoperate with anything other than HTTP protocol.

WebAPI is HTTP first. Depending on what you need, nothing prevent you from changing the content of a request to (for example) Protobuf. Of course, you won't be able to read it from a browser but if it's from Server to Server, well yeah!

That will allow you to actually leverage everything that has been built within WebAPI. Filters, advanced routing, middleware (in ASP.NET Core), authentication, caching, etc.

For me? WCF is dead for now.

justkao commented 8 years ago

You may want to take a look here: https://github.com/justkao/Bolt It's a library build on top of AspNetCore and is meant as replacement for WCF. It also supports some nice features like CancelationTokens and distributed sessions.

aspnet-hello commented 6 years ago

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.