[WCF] - 使用 [DataMember] 标记的数据契约需要声明 Set 方法
WCF 数据结构中返回的只读属性 TotalCount 也需要声明 Set 方法。
[DataContract]
public class BookShelfDataModel
{
public BookShelfDataModel()
{
BookList = new List<BookDataModel>();
}
[DataMember]
public List<BookDataModel> BookList { get; set; }
[DataMember]
public int TotalCount { get { return BookList.Sum(t => t.Count); } set { } }
}
未声明 Set 方法将抛出异常如下:
System.Exception: {"ClassName":"System.ServiceModel.CommunicationException","Message":"An error occurred while receiving the HTTP response to http://localhost:6274/TestService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.","Data":{},"InnerException":{"ClassName":"System.Net.WebException","Message":"The underlying connection was closed: An unexpected error occurred on a receive.","Data":{},"InnerException":{"ClassName":"System.IO.IOException","Message":"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.","Data":{},"InnerException":{"NativeErrorCode":10054,"ClassName":"System.Net.Sockets.SocketException","Message":"An existing connection was forcibly closed by the remote host","Data":{},"InnerException":null,"HelpURL":null,"StackTraceString":" at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)\r\n at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nReceive\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Sockets.Socket\nInt32 Receive(Byte[], Int32, Int32, System.Net.Sockets.SocketFlags)","HResult":-2147467259,"Source":"System","WatsonBuckets":null},"HelpURL":null,"StackTraceString":" at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)\r\n at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)\r\n at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nRead\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem
[WCF] - 使用 [DataMember] 标记的数据契约需要声明 Set 方法的更多相关文章
- 跟我一起学WCF(7)——WCF数据契约与序列化详解
一.引言 在前面博文介绍到,WCF的契约包括操作契约.数据契约.消息契约和错误契约,前面一篇博文已经结束了操作契约的介绍,接下来自然就是介绍数据契约了.所以本文要分享的内容就是数据契约. 二.数据契约 ...
- WCF分布式开发步步为赢(7):WCF数据契约与序列化
本节继续学习WCF分布式开发步步为赢(7):WCF数据契约与序列化.数据契约是WCF应用程序开发中一个重要的概念,毫无疑问实现客户端与服务端数据契约的传递中序列化是非常重要的步骤.那么序列化是什么?为 ...
- WCF服务编程——数据契约快速入门
WCF序列化流程 序列化 默认用户自定义类型(类和结构)并不支持序列化,因为.NET无法判断对象状态是否需要反射到流. 用户自定义类的实例支持序列化 需要添加[Serialazable].若要允许可序 ...
- WCF中数据契约之已知类型的几种公开方式
WCF中传输的数据不想传统的面向对象编程,它只传递了一些对象的属性,但是自身并不知道自己属于什么对象,所以,他没有子类和父类的概念,因而也就没有Is-a的关系,所以在WCF中,如果想维持这种继承关系, ...
- 重温WCF之数据契约中使用枚举(转载)(十一)
转载地址:http://www.zhuli8.com/wcf/EnumMember.html 枚举类型的定义总是支持序列化的.当我们定义一个新的枚举时,不必应用DataContract特性,就可以在数 ...
- 重温WCF之数据契约和序列化(四)
一.数据契约 1.使用数据协定可以灵活控制哪些成员应该被客户端识别. [DataContract] public class Employee { [DataMember] public string ...
- WCF之数据契约
从抽象层面看,WCF能够托管CLR类型(接口和类)并将它们公开为服务,也能够以本地CLR接口和类的方式使用服务.然而,CLR类型却属于.NET的特定技术.由于面向服务的一个核心原则就是在跨越服务边界时 ...
- WCF契约之---服务契约 、数据契约、 消息契约
本篇博文只是简单说下WCF中的契约的种类.作用以及一些简单的代码示例.在WCF中契约分为服务契约.数据契约和消息契约.下面对这几种契约进行简单的介绍. 服务契约 服务契约描述了暴露给外部的类型(接口或 ...
- WCF 之 数据契约
前面几篇讲的都只能传递string类型的简单参数,数据契约就是用来解决如传递一个带有多个属性的Class类型的对象的. WCF推荐使用数据契约的方式实现数据的序列化.这部分的内容很好理解但是很重要,先 ...
随机推荐
- python中range语法
规则:一般不取最后一位 start: 计数从 start 开始.默认是从 0 开始.例如range(5)等价于range(0, 5); stop: 计数到 stop 结束,但不包括 stop.例如:r ...
- 怎么把分化成元,并且保留两位小数,用vue来做
<el-table-column prop="amount" label="申请提现金额" width="120" align=&qu ...
- jquery中语法初学必备
$(this).hide() - 隐藏当前元素 $("p").hide() - 隐藏所有段落 $(".test").hide() - 隐藏所有 class=&q ...
- 优化Unity游戏项目的脚本(上)
本文将由捷克独立游戏工作室Lonely Vertex的开发工程师Ondřej Kofroň,分享C#脚本的一系列优化方法,并提供改进Unity游戏性能的最佳实践. 在开发游戏时,我们遇到了游戏过程中偶 ...
- UK Biobank专题
这个时代的生信,统计遗传,不懂或不会用这个数据库就说不过去了. 看看10年GWAS里是如何定位和评价UK biobank的: For the near future, the UK Biobank i ...
- 网关 apache APISIX
网关 apache - 国内版 Binghttps://cn.bing.com/search?q=%E7%BD%91%E5%85%B3+apache&qs=n&form=QBRE&am ...
- git如何查找某个包含指定字符串的commit hash值?
答: git shortlog --format='%H|%cn|%s' | grep '需要查找的字符串内容'
- C++中操作符——学习笔记
1.箭头操作符 用于指针. 使用容器vector存指针,迭代器是指针需要 解引用后再解引用才是数据.图中漏掉了iter++ 记得要delete 2.算术运算符 %:获得余数. 优先级. 溢出: 除法的 ...
- vmware配置双网卡
最近在学习使用iptables做网关服务器,即SNAT设置 我们的宿主机有两块网卡,地址分别是: 192.168.6.108/24 192.168.66.119/24 我们的目标是在虚拟机VMware ...
- 获取IFC构件的位置数据、方向数据
获取IFC构件的位置数据.方向数据 std::map<int, shared_ptr<BuildingEntity>> map_buildingEntity = b_model ...