如何在Web表单中检索字典数据类型?

时间:2013-10-20 05:12:22

标签: c# wcf

我有一个返回Dictionary对象的WCF服务。我创建了一个ASP .NET Web应用程序并添加了一个Web表单来测试该服务。我在Web应用程序中添加了我的WCF服务引用。现在,在Web窗体中编写Button1_Click的代码时,我无法访问我的服务返回的Dictionary对象。代码如下所示: 请尽快建议解决方案。 感谢。

`using System;    
using System.Collections.Generic;    
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using WebApplication1.wsHashOps;  

namespace WebApplication1  
{   
    public partial class WebForm1 : System.Web.UI.Page   
    {   
        protected void Page_Load(object sender, EventArgs e)   
        {

      }

        protected void Button1_Click(object sender, EventArgs e)  
        {
            string input = TextBox1.Text;
            Service1 client = new Service1();
            string data = "";



            Dictionary<int, string> hh = client.getWsHashOperations(input);

            string input = TextBox1.Text;    
            Service1 client = new Service1();    
            string data = "";    
            Dictionary<int, string> hh = client.getWsHashOperations(input);        
}        
}        
} 

1 个答案:

答案 0 :(得分:0)

    KeyValuePair<int,string>[] hh = client.getWsHashOperations(input);

    string input = TextBox1.Text;    
    Service1 client = new Service1();    
    string data = "";    
    KeyValuePair<int,string>[] hh2 = client.getWsHashOperations(input);

您不能声明具有相同名称的两个变量。重命名其中一个。 此外,看起来它根据您的错误消息解析为KeyValuePair数组。试试上面的

您也可以在类似

的情况下使用var关键字
var hh = client.getWsHashOperations(input); 

这将隐式解析数据类型,同时仍保持类型安全性