Client for native ASP.NET service

Note that you will have strong cohesion between the client and the service if you use the controller to create the client. To avoid this, use the interface as in this example.

If you want to generate a client for a ASP.NET web service, then you don’t even have to add attributes to the service interface. Everything you need:

Step 1: Create controller

[ApiController, Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    [HttpGet]
    public async Task<WeatherForecast> GetAsync(DateTime date) =>
        new WeatherForecast(date: date, temperatureC: -25);
}

Step 2: Extract interface for your controller and add INClient interface

public interface IWeatherForecastClient : INClient
{
    Task<WeatherForecast> GetAsync(DateTime date);
}

[ApiController, Route("[controller]")]
public class WeatherForecastController : ControllerBase, IWeatherForecastClient { ... }

Step 3: Create client

IWeatherForecastClient client = NClientProvider
    .Use<IWeatherForecastClient, WeatherForecastController>(host: "http://localhost:8080")
    .Build();

Step 4: Send an http request

// Equivalent to the following request: 
// curl -X GET -H "Content-type: application/json" http://localhost:8080/WeatherForecast?date=2021-03-13T00:15Z
var forecast = await client.GetAsync(DateTime.Now);
Console.WriteLine($"Date {forecast.Date}: {forecast.TemperatureC}°C");