Hello,
In all samples and documentation I've read so far the model use by the controller is strongly typed and know at compile time (plugin model). I have a case on which the type is known at runtime and I am wondering if I should define my controller API like:
public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
This model works fine, however I am wondering if I am missing some neat feature of WebAPI.
MsdnDev
Member
2 Points
11 Posts
Dynamic message types
Feb 27, 2013 11:43 PM|LINK
Hello,
In all samples and documentation I've read so far the model use by the controller is strongly typed and know at compile time (plugin model). I have a case on which the type is known at runtime and I am wondering if I should define my controller API like:
This model works fine, however I am wondering if I am missing some neat feature of WebAPI.
Thanks,
Pedro
DarrellNorto...
All-Star
86615 Points
9629 Posts
Moderator
MVP
Re: Dynamic message types
Feb 28, 2013 09:45 AM|LINK
You can use the ExpandoObject. JSON.NET (the default JSON serializer) works great with ExpandoObjects.
More on ExpandoObjects:
http://msdn.microsoft.com/en-us/magazine/ff796227.aspx
http://www.codeproject.com/Articles/99039/ExpandoObject-in-Practice
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
MsdnDev
Member
2 Points
11 Posts
Re: Dynamic message types
Feb 28, 2013 04:26 PM|LINK
I'll look into that, thanks