Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

asp.net mvc - ASP net core, receive XML as plain string?

I just need to accept an XML file and forward it to numerous endpoints in the quickest/most efficient way possible.

Following this Microsoft example (a basic ASP net Core 5 MVC API) I can accept XML files POST(ed) via Postman, by defining the object to be passed in a class and adding:

services.AddMvc().AddXmlSerializerFormatters().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

to the ConfigureServices method.

The issue here is this serialises the file and I don't need to access it, nor do I want the overheard of serialisation upon receipt and sending as well as latency and the potential volume of calls.

My Controller method looks like the following:

[HttpPost]
public async Task<ActionResult<root>> PostTodoItem(string todoItem)
{
    //_context.TodoItems.Add(todoItem);
    //await _context.SaveChangesAsync();

    return CreatedAtAction(nameof(GetTodoItem), new { id = 5 }, todoItem);
}

but the args received are just null?

Whats the best way to go about getting the raw XML string and filename that was submitted? Am I barking up the wrong tree with MVC/Core 5? Best regards

question from:https://stackoverflow.com/questions/65643528/asp-net-core-receive-xml-as-plain-string

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...