c# - How to read XML from ASP.NET Web API? -


i have web api read xml , pass appropriate model processing.

how can receive xml coming in? datatype should use?

do use streamreader, streamcontent or xmldocument or other?

asp.net web api uses content negotiation automatically deserialize incoming http request model class. out of box, this work xml, json, or wwww-form-urlencoded message.

public class computercontroller : apicontroller {     public void post(computerinfo computer)     {         // use computer argument     } } 

create model class maps properties of xml.

public class computerinfo {     public string processor { get; set; }     public string harddrive { get; set; } } 

this incoming xml deserialized hydrate computer parameter in post method.

<computerinfo>    <processor>amd</processor>    <harddrive>toshiba</harddrive> </computerinfo> 

if whatever reason want manually read , parse incoming xml, can this

string incomingtext = this.request.content.readasstringasync().result; xelement incomingxml = xelement.parse(incomingtext); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -