Webservice, hashtable?

P

Peter Kirk

Hi

I am trying to write a web service. This web service is a "generic
webservice" for our solution - that is, it should be able to return
different data depending on who calls it.

For example, we have 5 possible data items: name, address, company,
creation_date, telephone
(in reality there are 100s of possible data).

The companies who call our webservice can "subscribe" to a subset of this
data: maybe only name & address for example. So when they call the
webservice they receive only name & address back. Another company might
receive only name & telephone number.

(Configuration on the webserver determines what data is relevant for each
company, and they supply their "company id" when they call the web service).

What is a good type of data object to use as the return value? I thought of
a hastable, with key = "name" or "address" for example, and value as the
value. But now I am in doubt if a web service can return hashtables, or if
there might be a better data type anyway.

Thanks for any advice,
Peter
 
B

Biren Prajapati

I think you will be able to use hashtable for return type as hashtable
implements ISerializable interface. Webservice can use datatypes which
can be serialized. So, you will be able to use hashtable.
 
V

Vadym Stetsyak

Don't you think that returning hashtable will introduce overhead?

Another way may be returning "name-value" collection. where name is
"address", "telephone", etc and value stands for real value of this names.
 
M

Mark Rae

I think you will be able to use hashtable for return type as hashtable
implements ISerializable interface. Webservice can use datatypes which
can be serialized. So, you will be able to use hashtable.

Would a non-Microsoft client be able to work with a webservice which
returned a hashtable? E.g. would a ColdFusion solution know what to do with
a serialised hashtable?

Just curious...
 
G

Guest

Hi,

I think you need to rethink on the generic structure and what should be
returned. Returning business entity objects from web methods might be a
better idea. Are you sure that there isn't an business entity that could be
returned (which is common across all companies and could be filterd as per
the company id)?

It's not directly possible to return types that implement IDictionary (they
are not XmlSerializable). Hence it is not directly possible to return a
hashtable. However, you could use a workaround as mentioned here:
http://msmvps.com/blogs/rakeshrajan/archive/2006/01/15/81105.aspx

Note that when you return such custom classes, from web methods, they would
Xml Serialized, which means the response would be in XML. Thus, non-.NET
clients would get an Xml based response, which they would be able to parse.
 
B

Biren Prajapati

OOPS!..............I was wrong. We can't return hashtable. As Rakesh
said, it implements IDictionary so, we can't return hashtable from
webmethod.
 
G

Guest

Peter,
Most webservices of this type define a "YourMethodResult" class that
contains the various data items, and a "YourMethodResults collection" class
of these objects. This is defined in the WSDL contract and is normally
sufficiently "cross platform" to work with any client application.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top