0

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);        
}        
}        
} 
4

1 に答える 1

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);

同じ名前の 2 つの変数を宣言することはできません。それらのいずれかの名前を変更します。また、エラー メッセージに基づいて KeyValuePair 配列に解決されるようです。上記を試してください

このような場合に var キーワードを使用することもできます

var hh = client.getWsHashOperations(input); 

これにより、型の安全性を維持しながら、暗黙的にデータ型が解決されます

于 2013-10-20T05:15:34.977 に答える