471,319 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Webservice, hashtable?

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

Jan 31 '06 #1
7 9452
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.

Jan 31 '06 #2
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.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:uF**************@TK2MSFTNGP10.phx.gbl...
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


Jan 31 '06 #3
"Biren Prajapati" <se*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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...
Jan 31 '06 #4
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/.../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.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.rakeshrajan.com/
"Peter Kirk" wrote:
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


Jan 31 '06 #5
OOPS!..............I was wrong. We can't return hashtable. As Rakesh
said, it implements IDictionary so, we can't return hashtable from
webmethod.

Jan 31 '06 #6
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Peter Kirk" wrote:
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


Jan 31 '06 #7
Check my article on returning custom classes from a web service at
http://www.dalepreston.com/Blog/2005...-from-web.html.

HTH
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Peter Kirk" wrote:
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


Jan 31 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by jerome | last post: by
1 post views Thread by Monster | last post: by
1 post views Thread by Matt Kemmerer | last post: by
reply views Thread by mr t | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.