WCF扼流圈与否]性能;设置&QUOT ;.任何解决方法吗?

编程入门 行业动态 更新时间:2024-10-22 10:36:04
本文介绍了WCF扼流圈与否]性能;设置&QUOT ;.任何解决方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一些类,我路过作为服务方法的结果,那类有一个只能获得属性:

I have some class that I'm passing as a result of a service method, and that class has a get-only property:

[DataContract] public class ErrorBase { [DataMember] public virtual string Message { get { return ""; } } }

我在服务端得到一个例外:

I'm getting an exception on service side:

System.Runtime.Serialization.InvalidDataContractEx​​ception:未设置  方法类型MyNamespace.ErrorBase'属性'信息'。

System.Runtime.Serialization.InvalidDataContractException: No set method for property 'Message' in type 'MyNamespace.ErrorBase'.

我必须有这个属性,因为只有消气,我不能让用户为其分配一个值。任何解决办法,我可以使用?还是我错过了一些附加的属性?

I have to have this property as only getter, I can't allow users to assign it a value. Any workaround I could use? Or am I missing some additional attribute?

推荐答案

给消息的公共的getter但保护二传手,所以只有子类(与DataContractSerializer的,因为它欺骗:)可以修改的值。

Give Message a public getter but protected setter, so that only subclasses (and the DataContractSerializer, because it cheats :) may modify the value.

更多推荐

WCF扼流圈与否]性能;设置&QUOT ;.任何解决方法吗?

本文发布于:2023-05-28 12:30:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/320934.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!