Sharing a class or struct definition in web services

  • Thread starter Thread starter A.M
  • Start date Start date
A

A.M

Hi,

Using c# language,
I am developing a web service that needs to return mutiple values. I am,
therefore, returning a class contains mutiple values to be returned.
So the web method's definition is like this:
[WebMethod]
public LocationResult GetClosestPoint(string Licence,string Location, int
r,bool ReturnImage)

The problem is I have to have the definition of LocationResult in all client
projects.

Is there any better way to do this?
What is the best way to share the definition of LocationResult between
client applications?
Shouldn't I use struct instead of class?

Any help would be apprecited,
Alan
 
Hi Alan:

A struct is still a type that a client side tool will need to generate
a proxy for. One way to avoid this would be to return an XML Document
or fragment, but there are tradeoffs. Instead of having intellisense
and compile time checking of the LocationResult properties, the client
will need to dig values out of XML, say with XPath. Each approach has
good points and bad points, which one to choose really depends on many
factors.

Strictly speaking the definition is not shared, because the clients do
not need an assembly or dll file to use LocationResult. The wsdl.exe
tool will give the client a local definition by reading the web
service description.
 
Hi Alan,

I think Scott's suggestion is reasonable. Also, if the client apps are all
using .net , and geneate the client proxy class via WSDL.EXE. Then, the
wsdl.exe will automatically generate the clientside "LocationResult"
class proxy for the consumer app. If you have any other question, please
feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Thank you for help.

What are the advantages and disadvantages of using struct or class in this
situation ?

Alan
 
Generally speaking I'd favor a class, but it really depends on how
you'll use LocationResult. If the code is always inserting and
retrieving a LocationResult from an ArrayList, then there is a perf
penalty for boxing, so a reference type class would probably be a
better fit.
 
Thanks Scott.
Scott Allen said:
Generally speaking I'd favor a class, but it really depends on how
you'll use LocationResult. If the code is always inserting and
retrieving a LocationResult from an ArrayList, then there is a perf
penalty for boxing, so a reference type class would probably be a
better fit.
 
Back
Top