I want to return the Dictionary collection from the webservice. Since we could not directly return Dictionary Type from the webservice, I made the Serializable Dictionary as described in this link
It is fine and I could return the collection as xml below:
<?xml version="1.0" encoding="utf-8"?>
<SerializableDictionaryOfStringString xmlns="http://tempuri.org/">
<Item>
<Key>
<string xmlns="">k1</string>
</Key>
<Value>
<string xmlns="">abcdef</string>
</Value>
</Item>
<Item>
<Key>
<string xmlns="">k2</string>
</Key>
<Value>
<string xmlns="">xyz</string>
</Value>
</Item>
</SerializableDictionaryOfStringString>
However, the problem occurs when consuming this webservice. Instead of the SerializableDictionary Return Type, my web service method shows the return data type as DataSet. I don’t know how to handle the return data and utilize because although it returns as the Dataset, it is not actually the dataset and I could not do anything with it such as bind to gridview, ds.tables[0], etc….
So, how can I manipulate the return data from the webservice?
A dictionary is not the most logical choice for a DTO (Data Transfer Object).
Take a step back, what do you want to return from Server to Consumer?
I think it is just
Add the
[WebMethod],[Serializable]or[OperationContract],[DataContract]attributes as necessary.And then it is up to the Client to create a Dictionary from the List is that’s convenient.