How do we preserve the object type in json string when sending data to asmx web service in .net 2.0?
for example:
class A{
string name;
}
class B : A {
string address;
}
and the web method:
[WebMethod]
public void PushJson(A obj){
B b = (B) obj;
}
Now in above example scenario, lets say, i send {"obj":{"name":"waqas","address":"sweden"}} then how can i force my json string to act as type of class B, so that it can be accepted by web method as an object of class A and further parsed back into object of class B? in short, how to preserve polymorphism in json?
I've noticed that the compiler throws me System.InvalidCastException when ever i try to execute such kind of pattern
P.S. I've noticed that .net adds __type for complex objects while serializing into json. Is it possible that we can include this key to help .net to automatically parse json string with correct class type?
any help/suggestion would be helpful.
Update:
If we observe carefully the wsdl of an asmx web-service, so the objects whose classes inherits parent classes are containing something like <s:extension base="tns:ParentClassName">. I think this extension part is the thing which I may need to convert into Json. Any idea regarding this?