[英]How to get constructor from server on client side in C#?
On my client side, I want the default C# constructors from my WCF service C# classes. 在客户端,我希望从WCF服务C#类中使用默认的C#构造函数。 There reason we want to do this is to have the default values from the server side classes on the client side.
我们之所以要这样做,是为了使客户端的服务器端类具有默认值。 From the searches I've done, there are 2 ways to go about this:
从我完成的搜索中,有两种解决方法:
Is either one of these the "better" option? 其中一个是“更好”的选择吗? or is this heavily dependent on how often I would need a new instance of the object?
还是这在很大程度上取决于我需要该对象的新实例的频率?
EDIT: We tried using [System.Runtime.Serialization.OnDeserialized]
seen here but it's not working. 编辑:我们尝试使用此处看到的
[System.Runtime.Serialization.OnDeserialized]
,但它不起作用。 We are also not using the DataContract
attribute in our class, we use ServiceKnownType
instead 我们也没有在类中使用
DataContract
属性,而是使用ServiceKnownType
I think you can try using OnDeserializing
attribute 我认为您可以尝试使用
OnDeserializing
属性
[System.Runtime.Serialization.OnDeserializing]
private void OnDeserializing(StreamingContext ctx)
{
// Here set your default values
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.