由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults

由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribute 或从 <serviceDebug> 配置行为)以便将异常信息发送回客户端,或打开对每个 Microsoft .NET Framework SDK 文档的跟踪并检查服务器跟踪日志。

客户端调用WCF的时候报上面的错误,WCF只能序列化基础的数据类型,简单说只需要给客户端类上标记 [Serializable] 可序列化类问题就决绝了、

cs 复制代码
namespace ConsoleApplication1
{
    public class Program
    {
        static void Main(string[] args)
        {
            //获取数据
            BLL bll = new BLL();
            List<TB_StoreInfo> list = bll.GetModelList();//TB_StoreInfo = 客户端的数据模型

            //服务端 TB_StoreInfo 类
            List<ServiceReference1.TB_StoreInfo> list_StoreInfo = new List<ServiceReference1.TB_StoreInfo>();

            //TB_StoreInfo(客户端)类是无法直接赋值给ServiceReference1.TB_StoreInfo类
            //需要序列化TB_StoreInfo类  加  [Serializable]

            foreach (TB_StoreInfo item in list)
            {
                ServiceReference1.TB_StoreInfo _storeInfo = new ServiceReference1.TB_StoreInfo();
                _storeInfo.ID = item.ID;
                _storeInfo.Name = item.ID;
                _storeInfo.CreateDate = item.CreateDate;
                list_StoreInfo.Add(_storeInfo);
            }

            //然后就可以调用服务进行传参或返回值操作了,我这里是用来传递参数用的
            ServiceReference1.Check check = new ServiceReference1.Check();
            bool result = check.GetToList(list_StoreInfo);

            Console.ReadKey();
        }
    }

    public class BLL
    {
        private readonly DAL dal = new DAL();
        public List<TB_StoreInfo> GetModelList()
        {
            return dal.GetModelList();
        }
    }

    public class DAL
    {
        public List<TB_StoreInfo> GetModelList()
        {
            return new List<TB_StoreInfo>();
        }
    }
    [Serializable]
    public class TB_StoreInfo
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public DateTime CreateDate { get; set; }
    }
}
相关推荐
齐鲁大虾37 分钟前
新人编程语言选择指南
javascript·c++·python·c#
加号31 小时前
【C#】 WebAPI 接口设计与实现指南
开发语言·c#
unicrom_深圳市由你创科技2 小时前
上位机开发常用的语言 / 框架有哪些?
c++·python·c#
xiaoshuaishuai84 小时前
C# ZLibrary数字资源分发
开发语言·windows·c#
Eiceblue6 小时前
C# 实现 XLS 与 XLSX 格式双向互转(无需依赖 Office)
开发语言·c#·visual studio
aini_lovee7 小时前
基于C#的三菱PLC串口通信实现方案
服务器·网络·c#
光泽雨7 小时前
c#MVVM中的消息通知机制
服务器·c#
江沉晚呤时7 小时前
C# 整型溢出处理机制:checked 与 unchecked 上下文解析
c#·.net
yngsqq9 小时前
Vlookup用法
c#
bitt TRES10 小时前
如何使用C#与SQL Server数据库进行交互
数据库·c#·交互