简体   繁体   English

如何在C#中从客户端的服务器获取构造函数?

[英]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: 从我完成的搜索中,有两种解决方法:

  1. When I need a default instance of the object I make a server call that returns me the default instance 当我需要对象的默认实例时,我会进行服务器调用以返回默认实例
  2. I create a client side C# class which inherits from the server side C# class and copy paste the constructor and use this constructor 我创建一个从服务器端C#类继承的客户端C#类,并复制粘贴该构造函数并使用此构造函数

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.

相关问题 使用来自客户端 C# 的服务器端 PHP 代码 - Using server side PHP code from client side C# 如何使用javascript从客户端获取c#timezoneinfo类的客户端时区ID - How to get the client timezone id for c# timezoneinfo class from client side using javascript 如何在C#中的应用程序中在客户端获取远程服务器的日期和时间? - How can I get the remote server's date and time at the client side in my application in c#? C# 客户端:如何从 SQL Server 获取当前日期时间? - C# client : how to get current datetime from SQL Server? 如何在C#中从客户端的主机名和端口号在Web服务器上创建套接字? - How to create a socket on client side to web server from its hostname and Port number in C#? C#从客户端获取文件位置 - C# get file location from client-side 从客户端获取 C# 中的当前 ip 地址 - To get current ip address in c# from client side 如何通过 JavaScript 从服务器端的 Z2567A5EC9705EB7AC2C98403 - How can I call client side C# program function via JavaScript from web page on server side? 如何接收和保存从客户端(使用Ajax进行J查询)发送到服务器端(ASP.net C#)的数据? - How to receive and save the data sent from client side (J-query using Ajax) to server side (ASP.net C#)? 如何从存储在C#.net客户端的下拉框中显示的proc n中获取数据? - how to get the data from stored proc n show on the dropdownbox in c# .net client side?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM