Question: How do you develop a web service that uses unknown types?
The ideas is that my web service performs a generic function. I want
anyone to be able to consume it, but I can't know what type of objects
they are going to pass to in (like I said it performs some generic
functionality - I don't want to recompile it ever).
So I create a simple web service with with a method like:
string GetTypeInfo(object t){
return t.GetType().ToString();
}
I want to consume it with something like:
string s = WebService.GetTypeInfo(new Widget());
Now the big question:
The Widget type is NOT referenced in the web service (the whole point
is its generic remember). Now to me it makes sense that the client
(web service consumer) would serialize the object to xml, and pass the
xml and xsd describing the object over the wire via soap. The server,
would deserialize the xml to an object using the xsd by doing the
following: if the type is unknown, the deserializer could define a new
type via system.refelection.emit and then create an instance of it and
populate it. Does this make any sense? Is there something built into
the webservices to do this? If not, has anyone tried to roll your
own?
So why would I want to do this? Because lets say you have a business
tier and a data tier that are loosely coupled. My business tier holds
my model and my data tier populates the model (using a persistance
framework like hibernate). I don't want to recompile my data tier
simply because my model changes - I want it to be LOOSELY coupled, but
I don't want to be tied to simple value types and strings (I want to
do something useful).
Thanks for taking to read and answer my question.
Mike