If create weatherforecast webapi with swashbuckle support.
then create a console application using a connected service which successfully builds the client.
this works fine for example
[HttpPost("Transform2")]
public IAsyncEnumerable<WeatherForecast> Create()
{
async IAsyncEnumerable<WeatherForecast> answer()
{
yield return new WeatherForecast
{
Date = DateTime.Now,
Summary = "",
TemperatureC = 1
};
}
return answer();
}
and the client code looks like this
using (var httpClient = new HttpClient(clientHandler))
{
var client = new swaggerClient("https://localhost:44330/", httpClient);
var works = await client.Transform2Async();
}
nice, but actually what I'm working towards is sending a stream of data to the server and having it process it and return some data back, so I've decided to do that using IFormFile.
i.e.
[HttpPost("Transform")]
public IAsyncEnumerable<WeatherForecast> Create(IFormFile file)
{
async IAsyncEnumerable<WeatherForecast> answer()
{
yield return new WeatherForecast
{
Date = DateTime.Now,
Summary = "",
TemperatureC = 1
};
}
return answer();
}
this seems to work when I invoke it from the swagger html documentation page, it prompts me for a file to upload and this invoked the required API call.
The problem is when I use it from a openapi connected service generated code. This maps the IFormFile to a stream client side (which doesnt seem unreasonable).
so like this, just send any old file.
using (var httpClient = new HttpClient(clientHandler))
{
var client = new swaggerClient("https://localhost:44330/", httpClient);
//var works = await client.Transform2Async();
using (var file = System.IO.File.OpenRead(@"....\Program.cs"))
{
var fails = await client.TransformAsync(file);
}
}
this then fails with
ReportWebAPIProxy.ApiException
HResult=0x80131500
Message=The HTTP status code of the response was not expected (400).
Status: 400
Response:
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-0db7c532df85014e9f53bd7afbfae292-0f8b0596dc7d6f43-00","errors":{"":["Failed to read the request form. Missing content-type boundary."]}}
Source=ReportWebAPIProxy
StackTrace:
at ReportWebAPIProxy.swaggerClient.<TransformAsync>d__16.MoveNext() in C:\Users\m_r_n\source\repos\ReportWebAPIProxy\ReportWebAPIProxy\obj\swaggerClient.cs:line 170
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at ReportWebAPIProxy.Program.<DisplayStudents>d__1.MoveNext() in C:\Users\m_r_n\source\repos\ReportWebAPIProxy\ReportWebAPIProxy\Program.cs:line 26
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at ReportWebAPIProxy.Program.<Main>d__0.MoveNext() in C:\Users\m_r_n\source\repos\ReportWebAPIProxy\ReportWebAPIProxy\Program.cs:line 11
This exception was originally thrown at this call stack:
ReportWebAPIProxy.swaggerClient.TransformAsync(System.IO.Stream, System.Threading.CancellationToken) in swaggerClient.cs
[External Code]
ReportWebAPIProxy.Program.DisplayStudents() in Program.cs
[External Code]
ReportWebAPIProxy.Program.Main(string[]) in Program.cs