我无法从 Wcf 返回列表类型

问题描述

[DataContract]
public class UserDetails
{
    string _userid;
    string tckimlik;
    string ad;
    string tarih;
    string aciklama;
    [DataMember]
    public string userid
    {
        get { return _userid; }
        set { _userid = value; }
    }
    [DataMember]
    public string Tckimlik
    {
        get { return tckimlik; }
        set { tckimlik = value; }
    }
    [DataMember]
    public string Ad
    {
        get { return ad; }
        set { ad = value; }
    }
    [DataMember]
    public string Tarih
    {
        get { return tarih; }
        set { tarih = value; }
    }
    [DataMember]
    public string Aciklama
    {
        get { return aciklama; }
        set { aciklama = value; }
    }
}

public interface IService1
{        

    [OperationContract]
    List<UserDetails> GetAllPersons();
}

上面给出的我的类 DataContract 和 OperationContract。 我的方法 GetAllPersons 类型的列表如下。

 public List<UserDetails> GetAllPersons()
    {
        List<UserDetails> userL = new List<UserDetails>();
        try
        {
            NpgsqlConnection con = new NpgsqlConnection("");
            con.Open();
            NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM RegistrationTable",con);
            NpgsqlDataAdapter sda = new NpgsqlDataAdapter(cmd);
            NpgsqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                UserDetails us = new UserDetails()
                {
                    userid = reader[0].ToString(),Tckimlik = reader[1].ToString(),Ad = reader[2].ToString(),Tarih = reader[3].ToString(),Aciklama = reader[4].ToString()
                };
                userL.Add(us);
            }
            con.Close();
            return userL;
        }
        catch (Exception)
        {

            throw;
        }
    }

上面的代码在 WCF 服务中。我想在 Xamarin 中调用 GetAllPersons 方法。但我有麻烦。我的 Xamarin 代码如下。

 void getVisitor()
    {
        List<ServiceReference1.UserDetails> getir = new List<ServiceReference1.UserDetails>();
        getir = service.GetAllPersonsAsync();
        
    }

当我想在服务中调用方法时,出现如下错误。

严重性代码描述项目文件行抑制状态 错误 CS0029 无法将类型“System.Threading.Tasks.Task”隐式转换为“System.Collections.Generic.List”XamarinCRUD C:\Users\Eyyub\source\repos\XamarinCRUD\XamarinCRUD \XamarinCRUD\MainPage.xaml.cs 59 活动

谁能指点一下,不胜感激! 最适合所有人! 我还检查了日志,但没有显示。有人说 WCF 不会(反)序列化 List 返回类型。这是真的吗?如果是,解决方案是什么?当我通过 FormApp 使用相同的服务时,工作正常。但 Xamarin 没有..

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...