I'm new to ASP.Net and I have the following scenario:
I have a .Net Framework project folder with several projects. All of them are configured .Net Framework 4.7.2 and I have a dependency I can not change at the moment. So migrating to .Net Core is not an option at the moment.
My question is the following:
What is the correct approach to add the functionality of a RESTful server with ASP.Net?
I don't want to implement a frontend. I just want to add a server to my projects.
In
https://learn.microsoft.com/en-us/dotnet/standard/choosing-core-framework-server
it says, "In most cases, you don't need to migrate your existing applications to .NET 5. Instead, a recommended approach is to use .NET 5 as you extend an existing application, such as writing a new web service in ASP.NET Core."
How should I do that?
I'm really confused. Please help me.
Maybe some hints or links to other pages are enough to lead me into the right direction :)
Kind regards
Chris
It basically depends on your future preference and time, If the organisation is pretty much aligned with .netcore what you can do is you can easily migrate .net framework project to .Net standard and create a new .Net core project with API endpoints defined and you can easily refer the .Net standard libraries directly to it.
https://learn.microsoft.com/en-us/dotnet/core/porting/
But if you want to stick to .Net framework libraries, you can create basic Asp.Net core web API with DotNetframework, It is not a legacy framework, it has the latest release within 3 months and it is also battle-tested, But you can only host in windows machines unlike .Net core which you can host in windows/linux
https://developer.okta.com/blog/2018/07/27/build-crud-app-in-aspnet-framework-webapi-and-angular
any .net project that running on a web server supports REST calls. In fact if you make a webmethod?
Say this code:
<WebMethod()>
Public Function HelloWorld() As String
If keyid <> 123 Then Exit Function
Return "Hello World from server"
End Function
Then right out of the box with ONLY the above code?
The above supports SOAP 1.1, 1.2, and post (REST) calls.
So there is no "concept" in asp.net that you "adopt" SOME kind of RESTful server - the server you use in this case is IIS, and it supports REST calls out of the box, and always did from day one to my knowledge. You MOST certainly have to run a web server, but making REST calls does not require a "special" RESTful server, but just in fact that you running a web server - in this case IIS or so called internet services.
If you already have a project that supports and API just add an additional controller, assuming the functionality is not closely related to existing functionality.
Related
I'm trying to use client-side Blazor to display some data, provided by existing WCF service. I was able to add a connected service reference, the proxy is generated. But when I'm trying to invoke it like this:
var client = new SoftConServiceClient();
await client.PingAsync(new PingRequest());
there is a bunch of errors, related to MonoTouch. By digging into the code of Mono, there is an explicit NotImplementedException in the constructor of the System.ServiceModel.DnsEndpointIdentity.
Am I right to assume that there is no way now to call legacy WCF service from Blazor client-side? If that's not the case, can anyone share a guide about how to properly do it?
Bonus question: if that is not possible, what would be the best option to approach this? Modify WCF to become REST-ish or just drop it and implement .net core api service?
Thanks a lot in advance!
Core does not support WCF very well instead of not at all. Especially in terms of authentication and security, such as the service created by using WS* binding. But for services created by using BasicHttpBinding or Restful styles services. We could invoke them normally on Core-based clients, whether using client proxy class or Channel Factory.
Please refer to below official repository.
https://github.com/dotnet/wcf
I suggest you re-construct your server project with BasicHttpBinding or using Asp.net WebAPI to create the backend service.
https://learn.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
Feel free to let me know if there is anything I can help with.
WCF is not supported in .NET Core out of the box, however there seems like there is a community project that is working on adding support for it in .NET Core
https://github.com/CoreWCF/CoreWCF
See What replaces WCF in .Net Core? for more info.
Am I right to assume that there is no way now to call legacy WCF
service from Blazor client-side?
Yes, you're right... WCF is not supported in Blazor client-side, and it won't be supported in the future. Microsoft has decided to stop supporting it as from .Net 5.0, and suggest to use Web Api instead.
Depending on how much you are invested in WCF, you may shift to Web API, perhaps gRPC, or go on using WCF, hoping that the efforts of the community to port and support WCF might succeed.
I was able to to put WCF 4.7.2 using techniques found with SoftCore in .Net 5.
I can also work SoftCore Hosted Example Blazor Server.
Based on the answer here: How to explain Katana and OWIN in simple words and uses?
Regarding the comment above, OWIN is not a framework. OWIN is a
specification on how web servers and web applications should be built
in order to decouple one from another and allow movement of ASP.NET
applications to environments where at the current state it is not
possible.
Prior to OWIN, when you are building ASP.NET application, you are
inheritedly bound to IIS due to the heavy dependency on System.Web
assembly.
System.Web is something that exist ever since ASP (non .NET version)
and internally contains many things that you might not even need (such
as Web Forms or URL Authorization), which by the default run on every
request, thus consuming the resources and making ASP.NET applications
in general lot slower than it's counterparts at i.e. Node.js.
So OWIN itself does not have any tools, libraries or anything else. It
is just a specification.
If OWIN is just a specification with Katana its .NET implementation in order for ASP.NET applications to not be bound with IIS, then in the case of ASP.NET Core applications working with Kestrell and another webserver like nginx (acting as a reverse proxy) why we would still need OWIN?
ASP.NET Core is an evolution of the Microsoft.Owin.*, what Microsoft refers to as Katana.
The Microsoft.Owin.* libraries are not available for .NET Core because ASP.NET Core has equivalent replacements for them. See https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/
I am looking at implementing Breeze into one of my web projects. Currently, the client has set up their project to run under MVC4 and Web.API v.1 with an Entity Framework 6 backend.
Looking at the Breeze web site, the instructions talk about running with Web.API v.1 and EF 4 or 5, or using Web.API v.2 and EF 6, but not my scenario.
Is it possible to run in this config or do I HAVE to run Web.API v.2 to get things to work correctly?
Sorry but we have made no effort to make that particular combination work and are unlikely to try. The possible MS technology combinations are endless. We live in DLL hell as it is and we can only support what we perceive to be the main paths.
However, Breeze is all open source and you are welcome to try it yourself. The source code is in the repo. Have at it.
Personally, I would try to persuade your client that moving to Web API v2 is a necessity.
I have an existing website that is currently using .Net 3.5 and must stay that way because of our sharepoint integration. I need to write a web service/web api that the website will interact with (a method to send an email, for example). I also need to write a windows service that is going to do the same thing. The windows service will probably be .Net 4.5.
What framework should I use for the web service/web api so both environments can interact with it the best?
The very nature of web services, soap or rest, is that they are platform agnostic. This also applies to .net versions, you can have whatever version at the server and another version at the client and this surely will work.
I am looking for guidance on how to start building a http REST server using C# and a SQL Server database?
Is there a recommended server framework for http web server? The same for REST services?
How should I start? Raising regular server and after that taking care of the SQL Server database?
Thanks.
I'm starting to evaluate REST frameworks for .Net and python. So far I like ServiceStack for .Net the best. It's simple, far easier to config than WCF, supports dependency injection, and seems to be fast.
When VS 11 and .Net 4.5 are completely released, Microsoft is also offering Web API. It can be used to build REST API's as well so it's worth looking into.
I haven't done enough research on Web API to see which would be better but those are some considerations for you.
Use OData. Have a look at Creating an OData API for StackOverflow including XML and JSON in 30 minutes
Consider using the new ASP.NET Web API:
ASP.NET Web API is a framework that makes it easy to build HTTP services . . . ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
It is currently in beta but was built specifically for building RESTful HTTP services in .NET, unlike WCF. See SO question WCF vs ASP.NET Web API for more details.
There are samples and video tutorials, and in one they are using Entity Framework models which can be backed by SQL. This SO question specifically covers that example: How to mix Entity Framework with Web API