Tuesday, 15 June 2010

.net - WCF to MVC Web API for WebInvoke Attribute (BodyStyle = WrappedRequest) -



.net - WCF to MVC Web API for WebInvoke Attribute (BodyStyle = WrappedRequest) -

i'm trying recreate wcf web service mvc web api has next attribute on web method:

[webinvoke(method = "*", bodystyle = webmessagebodystyle.wrappedrequest)]

vb:

<webinvoke(method = "*", bodystyle = webmessagebodystyle.wrappedrequest)> _

what mvc web api way of creating wrapped request?

i have same issue , couldn't find solution, however, below work-around for.

creating wrappedresponse name/value structure.

public class wrappedresponse<t> { public list<t> samplecollection { get; set; } public static wrappedresponse<t> getresult(list<t> list) { var result = new wrappedresponse<t>(); result.samplecollection = list; homecoming result; } }

returning wrappedresponse instance.

[route("products")] public ihttpactionresult get() { configuration.formatters.clear(); configuration.formatters.add(new jsonmediatypeformatter()); using (var context = new adventureworks2012entities()) { list<product> productslist = context.products.take(10).tolist(); var result = wrappedresponse<product>.getresult(productslist); homecoming ok(result); } }

.net wcf asp.net-web-api

No comments:

Post a Comment