You're at the service's end of the wire and you don't know your clients.
你正处于服务终端,你不了解你的客户。
Why would you choose one over the other?
你为什么选择一个而不是另一个?
3 个解决方案
#1
As a rule of thumb; when designing a type yourself it should be a class, unless the type represents a single value, in which case it should be a struct.
根据经验;在自己设计类型时,它应该是一个类,除非类型表示单个值,在这种情况下它应该是一个结构。
#2
Fredrik has the correct answer. I'll only add that you should keep in mind that the client will never see your Data Contract. It will be translated into XML Schema and will be included in the WSDL. On the client side, recall, it could be a Perl or even Classic ASP client - something that has no concept of value vs. reference semantics.
弗雷德里克有正确的答案。我只想补充一点,你应该记住,客户永远不会看到你的数据合同。它将被翻译成XML Schema,并将包含在WSDL中。在客户端,回想一下,它可能是Perl甚至是经典的ASP客户端 - 没有价值概念与参考语义的东西。
So value vs. reference is something that only matters to the service - not to the clients.
因此,价值与参考只对服务有意义 - 而不是对客户而言。
#3
Actually, John Saunders isn't totally correct. The WSDL generated by WCF does infact indicate whether or not the objects are value or reference types. When you have WCF on the client side, you can take advantage of this. Also, value vs reference has an impact on the isNullable attribute of various parts of the WSDL which can change the semantics.
实际上,约翰桑德斯并不完全正确。 WCF生成的WSDL确实指示对象是值还是引用类型。当您在客户端使用WCF时,您可以利用此功能。此外,值与引用对WSDL的各个部分的isNullable属性有影响,它可以更改语义。
Of course, you need to make sure that you don't paint yourself into an incompatibility corner - a nullable value type is not necessarily the same thing as a reference type (or even possible) in some client environments.
当然,您需要确保不要将自己描绘成不兼容的角落 - 在某些客户端环境中,可空值类型不一定与引用类型(甚至可能)相同。
#1
As a rule of thumb; when designing a type yourself it should be a class, unless the type represents a single value, in which case it should be a struct.
根据经验;在自己设计类型时,它应该是一个类,除非类型表示单个值,在这种情况下它应该是一个结构。
#2
Fredrik has the correct answer. I'll only add that you should keep in mind that the client will never see your Data Contract. It will be translated into XML Schema and will be included in the WSDL. On the client side, recall, it could be a Perl or even Classic ASP client - something that has no concept of value vs. reference semantics.
弗雷德里克有正确的答案。我只想补充一点,你应该记住,客户永远不会看到你的数据合同。它将被翻译成XML Schema,并将包含在WSDL中。在客户端,回想一下,它可能是Perl甚至是经典的ASP客户端 - 没有价值概念与参考语义的东西。
So value vs. reference is something that only matters to the service - not to the clients.
因此,价值与参考只对服务有意义 - 而不是对客户而言。
#3
Actually, John Saunders isn't totally correct. The WSDL generated by WCF does infact indicate whether or not the objects are value or reference types. When you have WCF on the client side, you can take advantage of this. Also, value vs reference has an impact on the isNullable attribute of various parts of the WSDL which can change the semantics.
实际上,约翰桑德斯并不完全正确。 WCF生成的WSDL确实指示对象是值还是引用类型。当您在客户端使用WCF时,您可以利用此功能。此外,值与引用对WSDL的各个部分的isNullable属性有影响,它可以更改语义。
Of course, you need to make sure that you don't paint yourself into an incompatibility corner - a nullable value type is not necessarily the same thing as a reference type (or even possible) in some client environments.
当然,您需要确保不要将自己描绘成不兼容的角落 - 在某些客户端环境中,可空值类型不一定与引用类型(甚至可能)相同。