Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在web表单中检索字典数据类型?_C#_Wcf - Fatal编程技术网

C# 如何在web表单中检索字典数据类型?

C# 如何在web表单中检索字典数据类型?,c#,wcf,C#,Wcf,我有一个返回字典对象的WCF服务。我创建了一个ASP.NETWeb应用程序,并添加了一个Web表单来测试此服务。我已经在web应用程序中添加了我的WCF服务引用。现在,在web表单中编写Button1_Click的代码时,我无法访问服务返回的Dictionary对象。代码如下所示: 请尽快提出解决方案。 谢谢 `使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.UI; 使用System.We

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

`使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用WebApplication1.wsHashOps;
命名空间WebApplication1
{   
公共部分类WebForm1:System.Web.UI.Page
{   
受保护的无效页面加载(对象发送方、事件参数e)
{
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
字符串输入=TextBox1.Text;
Service1 client=newservice1();
字符串数据=”;
Dictionary hh=client.getWsHashOperations(输入);
字符串输入=TextBox1.Text;
Service1 client=newservice1();
字符串数据=”;
Dictionary hh=client.getWsHashOperations(输入);
}        
}        
} 

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

无法将类型“WebApplication1.wsHashOps.arrayofkeyvalueofitstringkeyvalueofitstring[]”隐式转换为“Systems.Collection.Generic.Dictionary”。很抱歉,这是一个键入错误。只有一个hh对象。我还尝试使用KeyValuePair代替Dictionary,但仍然显示相同的错误。好的,你能发布wcf方法吗?是的,我知道我可以使用var,但是如何从var数据类型中提取每个Dictionary值?不能在这里发布,太长了。但是我可以告诉你,wcf方法的返回类型是Dictionary。好的,我相信这可能是因为wcf序列化字典有一些困难。看看这个
`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);        
}        
}        
} 
    KeyValuePair<int,string>[] hh = client.getWsHashOperations(input);

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