TTC*_*TCG 4 c# serialization dictionary web-services
我想从webservice返回Dictionary集合.由于我们无法直接从Web服务返回Dictionary Type,因此我按照此链接中的描述创建了Serializable Dictionary
这很好,我可以将集合作为xml返回:
<?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>
Run Code Online (Sandbox Code Playgroud)
但是,在使用此Web服务时会出现此问题.我的Web服务方法不是SerializableDictionary返回类型,而是将返回数据类型显示为DataSet.我不知道如何处理返回数据并使用,因为虽然它作为数据集返回,但它实际上不是数据集,我无法对它做任何事情,例如绑定到gridview,ds.tables [0]等. ...
那么,我如何操作来自webservice的返回数据呢?
字典不是DTO(数据传输对象)的最合理选择.
退后一步,你想从服务器返回消费者?
我认为这只是
class MyDTO { public string Key {get; set; } public string Value {get; set; } }
public List<MyDTO> Servermethod() { ... }
Run Code Online (Sandbox Code Playgroud)
添加[WebMethod],[Serializable]或者[OperationContract],[DataContract]所需属性.
然后由客户端从列表中创建一个字典是方便的.