0
I’m trying to make a comeback in mine Controller
with FormatFilter
.xml
, but I get the 406.
Controller:
[HttpGet("xml/loja/{id}/{format}"), FormatFilter]
[Produces("application/xml")]
[AllowAnonymous]
public async Task<ActionResult<filterResultSet>> GetXmlLoja(
[FromHeader] Guid userId,
[FromHeader] string fileName,
Guid id
)
{
//FormatFilterAttribute format = FormatFilterAttribute.GetCustomAttribute(XmlDocument)
//if (!_mapaRelatorioBO.Exists(id).Result) return NotFound(new { message = "MapaRelatorio não existente!" });
//if (userId == null) return BadRequest(new { message = "Usuário não informado!" });
return await _mapaRelatorioBO.GetXmlLoja(id, fileName);
}
Startup.Cs
services.AddMvcCore(options =>
{
options.FormatterMappings.SetMediaTypeMappingForFormat
("xml", MediaTypeHeaderValue.Parse("application/xml"));
options.FormatterMappings.SetMediaTypeMappingForFormat
("config", MediaTypeHeaderValue.Parse("application/xml"));
options.FormatterMappings.SetMediaTypeMappingForFormat
("js", MediaTypeHeaderValue.Parse("application/json"));
})
.AddFormatterMappings();
services.AddMvc(options =>
{
options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
});
Return
The format of the submission is: filterResultSet filter = new filterResultSet();
namespace GI.NET.Insights.Dominio.Xml
{
public class EstruturaLojaXml
{
}
// NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0.
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http", IsNullable = false)]
public partial class filterResultSet
{
private filterResultSetFilterResult filterResultField;
/// <remarks/>
public filterResultSetFilterResult filterResult
{
get
{
return this.filterResultField;
}
set
{
this.filterResultField = value;
}
}
} ...
by the result that should be successful the Swagger shows me so:
How are you sending?
– novic
I asked the question. :)
– Rebeca Nonato
It seems to me that your request does not accept to receive an xml response
– Leandro Angelo
Example Value is the example that should be sent, if you are sending this xml?
– novic
In Swagger, after clicking on
Try out
just below the execute button on the right has a select "Response content type", tried to change to "application/xml"?– Leandro Angelo
is has several aspects equal @Leandroangelo quoted for that all this works...
– novic
@Leandroangelo has already changed, when I run the project. I put his image complete.
– Rebeca Nonato
@novic the Structurelojaxml class mounts the full XML object, as generated by the visual studio itself. from the filterResult object. He’s too big, so I didn’t put it all.
– Rebeca Nonato
get? method are enough problems that I’ve encountered, what you want to do basically?
– novic
Another application will call mine, and I have to return an xml to it. Practically this.
– Rebeca Nonato
When I call my application, it reads all of it. But, on the 406 return. Something from Header. I even found a possible solution, but it only works for the core >3.0 https://docs.microsoft.com/pt-br/aspnet/core/web-api/advanced/formatting?view=aspnetcore-5.0
– Rebeca Nonato
how is it calling?
– novic
For now, by the same Swagger, inserting the id, and the format.
– Rebeca Nonato
And also did not understand, why the filter if you have a unique route to return xml
– Leandro Angelo
@Leandroangelo, are attempts to make it work, none worked. srsrsrsrsr I managed to make it work with core 3.0. but with this not yet.
– Rebeca Nonato
So I have an example with the latest version v5 and works perfectly do not need to write anything in the class just confiugrar and use and even print xml or json
– novic
I checked my class. E some
System.Xml.Serialization
were not working. Hence error 406. It was necessary to redo them. (were automatically generated by Visual Studio from an . xml file)– Rebeca Nonato