如何返回从一个WebService哈希表? [英] How to return a HashTable from a WebService?

查看:356
本文介绍了如何返回从一个WebService哈希表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的web服务返回的所有字符串变量。现在,我想修改我的服务,以便它可以返回Hashtable对象。这是我的WebService的入口点(法)的签名:

My webservice is returning all string variables. Now I want to modify my service so that it can return HashTable object. This is the signature of my WebService entry-point(method):

public void getPrevAttempts(string fbUserId, string studentId, string assessmentId, out string isAuthenticated, out HashTable attempts) 

在哈希表中的记录插入表格的结果SQL查询。每当我tryimg运行我的服务,我越来越重定向到accessdenied.htm页面(因为我的web.config有这个条目<的customErrors模式=ON的defaultRedirect =accessdenied.htm /> )。有没有办法返回的HashTable 或SQL查询的结果?

The records in the HashTable are inserted form the result of an SQL query. Whenever I'm tryimg to run my service, I'm getting redirected to accessdenied.htm page(Since my Web.config has this entry <customErrors mode="On" defaultRedirect="accessdenied.htm"/>). Is there any way to return HashTable or the result of SQL query?

例外:类型System.Collections.Hashtable不支持因为它实现IDictionary的。

推荐答案

序列化数据,以JSON字符串,并返回给客户端。

Serialize the data to JSON string and return to the client.

var serializer = new JavaScriptSerializer();
HashTable ht = New HashTable();
//Populate ht.
response = serializer.Serialize(ht) // This will serialize the data to JSON format.

在客户端,使用反序列化

On the Client side, de-serialize using

httpResponse = JSON.parse(response); //httpResponse will have key value pair data as you created in server.

这篇关于如何返回从一个WebService哈希表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆