G
Guest
Is there a way to instantiate an object whose type isn't known until runtime?
Something comparable to Java's Class.newInstance()?
Thanks,
- Jim Robertson
Something comparable to Java's Class.newInstance()?
Thanks,
- Jim Robertson
Jim Robertson said:Is there a way to instantiate an object whose type isn't known until
runtime?
Something comparable to Java's Class.newInstance()?
Alvin Bruney said:The webservice exposes a WSDL document for that vary purpose. Append wsdl to
the end of the URL and it will return the valid schema for the webservice.
You can simply query the returned XML to find what you need without
resorting to reflection and the like.
From a design perspective, that's a horrid idea because
it imposes a cost on a call to a webservice which is equal to probing and
retrieving parameters before making the actual call. Added to the turtle
performance of an XML webservice and you have a recipe for disaster in high
concurrency situations. A better approach is to program to the final
webservice API since its implementation should be set in stone after
release.
--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
------------------------------------------------------------
Dave Hall said:I have the almost the same question, but it's regarding a web service
object. The URL is known, so I think I can avoid messing with UDDI, but I
want to discover the methods (specifically the parameters to a known
method)
at run time. The idea is this: Suppose a particular web service exposes a
Person object. It has a method such as SetInfo(int age, string firstName,
string lastName). I have a collection of personal info from another source
that I want to pass to this web service. The info I have available incudes
age, firstName, middleName, lastName, maidenName, nameSuffix and SSN. The
web service will eventually be changed to accept some of the additional
information I have available and when it does, I want to pass them to the
corresponding parameters without recompiling my code. For example, SetInfo
may be changed to look like this: SetInfo(int age, string firstName,
string
middleName, string lastName, string SSN). In that case, I want to
"discover"
the parameter names at run time and provide the corresponding values from
my
available data. If the Person object was a "normal" .NET component, I
would
know how to use reflection to learn the methods and properties at run time
and to invoke them. If the Person.SetInfo method was a stored procedure, I
could loop through the parameters collection and learn their names. I
haven't worked with .NET remoting yet, so I don't know if that's even
applicable with a web service. How can I do something comparable with a
web
service object?
Thanks,
Dave