Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Microsoft.AspNet.WebApi.Client supported in .NET Core or not?

I'm currently trying to do some JSON formatting using the HttpClient in .NET Core and MediaTypeFormatters. Especially the function "ReadAsAsync(..., MediaTypeFormatter, ...)" (https://msdn.microsoft.com/de-de/library/system.net.http.httpcontentextensions.readasasync(v=vs.118).aspx) which was available in .NET Framework in the HttpContent-Class would be very helpful. As far as I understood, it can be found in the NuGet package Microsoft.AspNet.WebApi.Client but I cannot download it because it is not supported in .NET Core.

Though I have read, that it should be:

  • Where is HttpContent.ReadAsAsync?
  • https://www.techrepository.in/consuming-rest-api-methods-in-net-core-mvc-application

I know that it is possible to do the formatting using Newtonsoft and so on.

But does someone know, if that package will be available in .NET Core some day again? I could not find any information really...

like image 761
timothy3001 Avatar asked Mar 30 '17 12:03

timothy3001


People also ask

Can we use System web in .NET Core?

You can't use System. Web in . NET Core to access HttpContext. While it may be technically possible to add a reference to System.

What is Microsoft ASP.NET Webapi?

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the . NET Framework.

What platforms does .NET Core support?

ASP.NET Core is the open-source version of ASP.NET, that runs on Linux, Windows, macOS, and Docker.

What is the difference between ASP.NET Web API and ASP.NET Core Web API?

In ASP.NET Core, there's no longer any distinction between MVC and Web APIs. There's only ASP.NET MVC, which includes support for view-based scenarios, API endpoints, and Razor Pages (and other variations like health checks and SignalR). In addition to being consistent and unified within ASP.NET Core, APIs built in .


3 Answers

Update:

Microsoft.AspNet.WebApi.Client version 5.2.4 was released on 2018-02-12.

Thanks @whitney-kew @jaquez


The package is not fully compatible with dotnetcore now. However there's workaround for this. You have to edit project.csproj like below:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   <TargetFramework>netstandard1.4</TargetFramework>
   <PackageTargetFallback>portable-net451+win8</PackageTargetFallback>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.3" />
    <PackageReference Include="System.Runtime.Serialization.Xml" Version="4.3.0-*" />
    <PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0-*" />
  </ItemGroup> 
</Project>

Please refer to this github issue for details:

https://github.com/aspnet/Home/issues/1558

I think the new Microsoft.AspNet.WebApi.Client version (5.2.4) should fix this, but it's not released yet, maybe in late 2017.

like image 84
starshine wang Avatar answered Oct 19 '22 22:10

starshine wang


Microsoft.AspNet.WebApi.Client 5.2.4-preview1 is available now at https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/5.2.4-preview1, as of the first week of January 2018. I was able to add it to my .NET Core library today, and it builds successfully.

like image 22
Whitney Kew Avatar answered Oct 19 '22 22:10

Whitney Kew


In addition to the other answers, there's also the System.Net.Http.Json package that uses the new Json serializer instead of Newtonsoft's.

The usage is slightly different than using Microsoft.AspNet.WebApi.Client.

httpClient.GetFromJsonAsync<Type>(uri);

There's a number of other overloads as well.

like image 1
ESG Avatar answered Oct 19 '22 21:10

ESG