Re: How do I create an object?
From: Dave Hall (DHall_NoSpamPlease_at_deboy.com)
Date: 03/06/05
- Next message: Sean Hederman: "Re: When a service really starts"
- Previous message: Herr Lucifer: "Who can wrap it up?"
- In reply to: Alvin Bruney [ASP.NET MVP]: "Re: How do I create an object?"
- Next in thread: Jim Robertson: "Re: How do I create an object?"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 6 Mar 2005 00:57:33 -0500
I've looked at the WDSL document and I know it can provide the info I need.
It's a bit of a hassle to paste together all of the .NET components to
retreive the XML document via http then load it onto an XmlDocument so I can
navigate to the desired XmlNodes which specify the parameters to the Soap
method. I was hoping that there was another component already in the
framework which would handle much of this under the hood. I was envisioning
something like the way I would learn the parameter names for a local object
by retreiving a ParameterInfo array from System.Reflection, except that in
this case, I'd need to specify specify the Soap URL in addition to the type
name. It would work something roughly like this:
To get the parameter list for Person.SetInfo() method:
string soapUrl = http://Myweb.com/MyWebService/Person.asmx"
string soapMethodName = "SetInfo"
ParameterInfo[] params = GetSoapParameters(soapUrl, soapMethodName)
foreach(ParameterInfo param in params)
{
Console.WriteLine(param.ParameterType.Name + " " + param.Name);
}
As far as the performance hit is concerned, I understand that it would be
terrible if I did this with each call to the web service, but in practice, I
plan to do it only once when my application first starts, at which time, I
would maintain the params collection and use it each time I need to invoke
SetInfo. The web service interface isn't likely to be set in stone any time
soon, but it will probably change many times in the future. I don't want to
maintain the code that interfaces to it on an ongoing basis. That's why I'm
trying to make my code smart enough to work with any foreseeable changes in
the web service, which at this point consists only of changes to the names
and data types of particular parameters to SetInfo(). I've done similar
things with caching the parameters collection for a stored procedure at run
time, then looping through the parmeter names to determine which data I
needed to provide. That way, the stored procedure could be changed as needed
to facilitate new parameters. It's a pretty effective design as long as you
cache the parameter list once rather than retreiving it each time.
If you have any ideas about how to implement the GetSoapParameters() method
in the example above, I'd appreciate any suggestions.
Thanks,
Dave
"Alvin Bruney [ASP.NET MVP]" <www.lulu.com/owc> wrote in message
news:ukMnyUfIFHA.276@tk2msftngp13.phx.gbl...
> 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" <DHall_NoSpamPlease@deboy.com> wrote in message
> news:%23iTPbteIFHA.1860@TK2MSFTNGP15.phx.gbl...
> >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
> >
> >
> > "William DePalo [MVP VC++]" <willd.no.spam@mvps.org> wrote in message
> > news:eD$OfeRIFHA.1948@TK2MSFTNGP14.phx.gbl...
> >> "Jim Robertson" <JimRobertson@discussions.microsoft.com> wrote in
message
> >> news:430FB08F-EFF6-47C9-832D-C93C9AE80F18@microsoft.com...
> >> > Is there a way to instantiate an object whose type isn't known until
> >> > runtime?
> >> > Something comparable to Java's Class.newInstance()?
> >>
> >> Yup. Check the docs for Activator.CreateInstance().
> >>
> >> Just btw, like Java, .Net supports reflection so you'll be able to get
an
> >> instance of a class if you like and inspect it for methods and members
as
> >> well, if you have a need to do that.
> >>
> >> Regards,
> >> Will
> >>
> >>
> >>
> >
> >
>
>
- Next message: Sean Hederman: "Re: When a service really starts"
- Previous message: Herr Lucifer: "Who can wrap it up?"
- In reply to: Alvin Bruney [ASP.NET MVP]: "Re: How do I create an object?"
- Next in thread: Jim Robertson: "Re: How do I create an object?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|