473,942 Members | 17,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning a Dictionary from a webservice

I'm trying to return a HashTable froma WebMethod. This fails with a not
supported method because HashTable implements IDictionary. What I'm doing
right now instead is stuffing my data into a DataSet and then extracting my
data from the DataSet on the other side.

What I want to know is this: What is the easiest way to return something
similar to an associative array (HashTable) from a web service.
Sep 13 '06 #1
1 11311
"Matt Kemmerer" <Matt Ke******@discus sions.microsoft .comwrote in message
news:44******** *************** ***********@mic rosoft.com...
I'm trying to return a HashTable froma WebMethod. This fails with a not
supported method because HashTable implements IDictionary. What I'm doing
right now instead is stuffing my data into a DataSet and then extracting
my
data from the DataSet on the other side.

What I want to know is this: What is the easiest way to return something
similar to an associative array (HashTable) from a web service.
Always remember thtat web services are about platform independence, acheived
by sending and receiving XML, described by an XML Schema.

There is no such thing as "associativ e array" in XML Schema.

Instead, you probably want to return an array of key-value pairs. So, for
example, if your Hashtable had integer keys and a DateTime value, you might
define a schema like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace ="http://www.example.org/NewXMLSchema"
xmlns:tns="http ://www.example.org/NewXMLSchema">
<xs:element name="return">
<xs:complexType >
<xs:sequence>
<xs:element name="dictionar y" type="tns:Dicti onaryEntry"
minOccurs="0" maxOccurs="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexTy pe name="Dictionar yEntry">
<xs:sequence>
<xs:element name="key" type="xs:int" />
<xs:element name="value" type="xs:dateTi me" />
</xs:sequence>
</xs:complexType>
</xs:schema>

This can be serialized from and deserialized into a class like this:

public class result {

[System.Xml.Seri alization.XmlEl ementAttribute( "dictionary ")]
public DictionaryEntry[] dictionary;
}

[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="http://www.example.org/NewXMLSchema")]
public class DictionaryEntry {

[System.Xml.Seri alization.XmlEl ementAttribute( )]
public int key;

[System.Xml.Seri alization.XmlEl ementAttribute( )]
public System.DateTime value;
}
If a client needs to access this data in an associative manner, the client
can load the array elements into the client's version of an associative
array (assuming there is such a thing on the client platform).
Another way to think of this is that the important thing about your data is
that it's a collection of key-value pairs (and maybe that the keys are
unique, in which case that should be specified in the schema). Your client
shouldn't have to care whether you kept this data in a Hashtable or in a
relational database, or whether you kept it in pen and ink! You similarly
don't want to dictate how your client treats this data.

John
Sep 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
410
by: Karuppasamy | last post by:
H I have a WebService calling a Method in a Remote Object. The Remote method Returns an Object. This Webservice also returns the same object. All things are working fine when this Web Service is running in a Windows XP. But when I am trying to run the same webservice in a Windows 2000 Advanced Server Machine, I am getting the following error “System.Web.Services.Protocols.SoapException: Server was unable to process request. ...
0
2034
by: ksams | last post by:
Hi Hope this mail finds you in the best of health and in good sprit. I have a problem with Web Service in a Windows 2000 Advanced Serve Machine. I have a WebService calling a Method in a Remote Object. The Remot method Returns an Object. This Webservice also returns the same object All things are working fine when this Web Service is running in
0
1021
by: Sharon | last post by:
Hi all I have this web service function returning XML document Everytime i change something in the function / function signature I regenerate the web service obj by deleting and adding new webReference
5
19615
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
4
1229
by: Daniel | last post by:
I've been asking around and reading but I cannot find a definitive answer. I have customers that need information from our calendar application. The data will come from SQL Server 2000. The customers who use .net are able to read the datasets that the web service returns. I'm having problems when customers are using Java or CFMX. What is the proper way to "return" data from the webservice. This data will consist of multiple rows...
5
1803
by: Brian Richards | last post by:
I'm experiencing some wierd behavior with a Dictionary<T,U> class using foreach loops, such that the Key returned in the foreach is not contained in the dictionary. code: Dictionary<A, B> dict; ..... foreach(A key in dict.Keys) {
2
1642
by: Asim Qazi | last post by:
Hi All public class MyResponse { public bool m_bStatus; public string m_szErrorCode; public string m_szMessage; }
20
34216
by: Gustaf | last post by:
This is two questions in one really. First, I wonder how to convert the values in a Dictionary to an array. Here's the dictionary: private Dictionary<Uri, Schemaschemas = new Dictionary<Uri, Schema>(); Uri is the System.Uri class, and Schema is a class I made. Now, I want the class where this Dictionary is contained to have a property that returns all the values in this Dictionary. Like such: public Schema Schemas
1
1474
by: Ronchese | last post by:
Helllo. I need to return a XML from my WebService, but I'm not getting the result as a XML. I mean, instead of receiveing a tag (<xyy></xyz>), I'm receiving it encoded (with &lt; or &gt;). There is some right way to return the correct XML from my WebService? Just for example, the WebMethod looks like it:
0
10135
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9969
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11531
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11298
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4909
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.