首页 新闻 会员 周边

WCF:实体定义标记为 [DataContract(IsReference=true)]后的JSON序列化问题

0
悬赏园豆:40 [已关闭问题] 关闭于 2015-03-12 10:22

【背景:】

WCF为数据提供方,客户端通过HTTP方式访问请求数据,数据返回格式为为JSON

将实体XXX标记为 [DataContract(IsReference=true)]后通过访问出错,服务器错误提示如下:

 

The server encountered an error processing the request. The exception message is 'Error in deserializing body of request message for operation 'GetOrders'. The type 'XXXX' cannot be serialized to JSON because its IsReference setting is 'True'. The JSON format does not support references because there is no standardized format for representing references. To enable serialization, disable the IsReference setting on the type or an appropriate parent class of the type.'.

 

不知是否有碰到相同问题的园友,望指点一二。

PS:由于要兼容原来的服务调用。所以[DataContract(IsReference=true)]方案暂不考虑。

牛!的主页 牛! | 初学一级 | 园豆:21
提问于:2015-03-11 18:05
< >
分享
所有回答(2)
0

为什么要标记IsReference呢,去掉就不会报错的,客户端请求的时候,您指定某个方法返回string类型的值公布出去就行了

神牛003 | 园豆:513 (小虾三级) | 2015-03-11 23:14

系统采用了EF实体框架,为了保留实体的导航属性,所以统一将DTO都标记为[DataContract(IsReference=true)]。

支持(0) 反对(0) 牛! | 园豆:21 (初学一级) | 2015-03-12 08:34
0

经过一晚上的折腾,问题得以解决,主要参照了一篇老外的帖子:

由于谷哥被和谐,所以只能通过在线代理查看

目前初步试验成功。

牛! | 园豆:21 (初学一级) | 2015-03-12 10:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册