DataContract属性需要澄清 [英] Clarification needed for DataContract attribute

查看:105
本文介绍了DataContract属性需要澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 [DataContract] 属性产生怀疑。



我编写了如下代码:这里我没有提到我的测试类的 [DataContract] 属性。

I have getting doubt in [DataContract] attribute.

I have written my code like below: Here i am not mentioned [DataContract] attribute for my test class.

        class test
        {
          [Datamember]
           public string Strproperty
            {
              get;
              set;
            }
           [Datamemer]
           public string Strproperty2
            {
              get;
              set;
            }
        }


     class checktotal:Iservice
        {
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "test")]
        public string testmethod(test obj)
           {
               return obj.Strproperty+Strproperty2;
           }
        }



为此,我从客户端发送数据我正确地得到了值。

这里有必要使用 [DataContract] 属性那个测试类?

如果我删除 [Datamember] 测试类属性从client发送时出错。但是我没有得到eny错误即使我没有提到 [DataContract] Attrinbute。



请给我一个简短的解释,举例如此我可以理解何时给出该属性以及何时不给予该属性。





谢谢,

Satya Pratap。


For that i am sending data from client i am getting the values correctly.
here is it necessary to use [DataContract] attribute for that test class?
If i removed [Datamember] for test class property is getting error while sending from client.But i am not getting eny errors even if i am not mentioned the [DataContract] Attrinbute.

Please give me a brief explanation with example so that i can understand when to give that attribute and when do not give that attribute.


Thanks,
Satya Pratap.

推荐答案

请参阅我最近解释这个想法的答案,另请参阅引用的MSDN文章:如何将数据合同从C#/ WCF代码传递到托管C ++ [ ^ ]。



这两个属性定义了什么类型以及此类型的成员是数据联系的一部分,以及一些重要的细节。如果您不使用它们,它们不参与联系,或者在运行时期间序列化程序会抛出一些异常,例如,如果某些元数据是矛盾的。所有细节的完整解释不能是快速回答的问题 - 这是整个技术。不仅 System.Reflection ,还包括 System.Reflection.Emit



-SA
Please see my recent answer explaining the idea, see also the referenced MSDN article: how to pass a datacontract from a C#/WCF code to Managed C++[^].

These two attributes defines what type and what members of this types are part of data contact, as well as some important detail. If you don't use them, they don't participate in contact, or some exceptions will be thrown by the serializer during runtime, if, say, some metadata is contradictory. Full explanation of all the detail could not be a matter of Quick Answer — this is the whole technology. Not only System.Reflection, but even System.Reflection.Emit are involved.

—SA


这篇关于DataContract属性需要澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆