.Net Core 中使用Binding ServiceEndpoint后果

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhu7478848/article/details/83790180

问题:在将原有.Net Framework上的C#程序转换到.Net Core下运行时,为了能够不拆散原有程序结构,我们进行了最大程度的兼容移植。在使用过程中经常会出现 序列化保存的对象后,从文件反序列化读取时,出现乱码(就是各种???,还不报错,一进行类型转换的时候就是为空)。经过最后各种排查,原来在DLL加载的时候,程序对部分同一DLL加载了两次,出现了反序列化对象二义性的问题。
解决:最终确认是在程序中使用了

//WCFBinding创建
            Binding theBinding = CreateTcpBinding();
            //WCF终端设定
            ServiceEndpoint theEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IService)),
                theBinding,
                new EndpointAddress(theAddress + ServiceName));

            //WCFBehiver创建
            foreach (var op in theEndpoint.Contract.Operations)
            {
                var dataContractBehavior = op.Behaviors[typeof(DataContractSerializerOperationBehavior)] as DataContractSerializerOperationBehavior;
                if (dataContractBehavior != null)
                {
                    dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                }
            }

造成的上述问题。
猜想:因为有对该绑定后,他可能生成了一个对应副本,用于他所谓的网络传输

猜你喜欢

转载自blog.csdn.net/zhu7478848/article/details/83790180