Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Service: Want to Return Serializable Dictionary But It Shows DataSet

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?

like image 397
TTCG Avatar asked Apr 03 '11 14:04

TTCG


1 Answers

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

class MyDTO { public string Key {get; set; } public string Value {get; set; } }

public List<MyDTO> Servermethod() { ... }

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.

like image 100
Henk Holterman Avatar answered Oct 30 '22 11:10

Henk Holterman