由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 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; }
    }
}
相关推荐
江山如画,佳人北望12 小时前
C#程序入门
开发语言·windows·c#
与火星的孩子对话13 小时前
Unity进阶课程【六】Android、ios、Pad 终端设备打包局域网IP调试、USB调试、性能检测、控制台打印日志等、C#
android·unity·ios·c#·ip
future141213 小时前
C#每日学习日记
java·学习·c#
军训猫猫头17 小时前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
葬歌倾城1 天前
JSON的缩进格式方式和紧凑格式方式
c#·json
Eiceblue1 天前
使用 C# 发送电子邮件(支持普通文本、HTML 和附件)
开发语言·c#·html·visual studio
小小小小王王王1 天前
hello判断
开发语言·c#
金增辉2 天前
基于C#的OPCServer应用开发,引用WtOPCSvr.dll
c#
future14122 天前
C#学习日记
开发语言·学习·c#
傻啦嘿哟2 天前
Python 办公实战:用 python-docx 自动生成 Word 文档
开发语言·c#