I would like to accept a post from a 3rd party tool which posts a complex json object. For this question we can assume an object like this:
{
a: "a value",
b: "b value",
c: "c value",
d: {
a: [1,2,3]
}
}
my .net code looks like
asmx:
[WebMethod]
public bool AcceptPush(ABCObject ObjectName) { ... }
class.cs
public class ABCObject
{
public string a;
public string b;
public string c;
ABCSubObject d;
}
public class ABCSubObject
{
public int[] a;
}
This all works perfectly if I pass the object when it is wrapped and named "ObjectName":
{
ObjectName:
{
a: "a value",
b: "b value",
c: "c value",
d: {
a: [1,2,3]
}
}
}
But fails without the object wrapped in an named object. Which is what is posted.
{
a: "a value",
b: "b value",
c: "c value",
d: {
a: [1,2,3]
}
}
I can accept this or any post with a Handler (ashx), but is this possible using a vanilla .Net Webservice (asmx)?
I also tried combinations of:
[WebMethod(EnableSession = false)]
[WebInvoke(
Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate="{ObjectName}")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
I suspect UriTemplate or some missing BodyTemplate would work.