gpt4 book ai didi

.net - 单例和客户端激活对象(CAO),Remoitng

转载 作者:行者123 更新时间:2023-12-04 06:50:32 25 4
gpt4 key购买 nike

两者都执行相同的操作

MSDN

  • Singleton: ""Single Call 对象服务一个而且只有一个请求进来......"
  • CAO:“客户端激活对象 (CAO) 是根据客户端请求激活的服务器端对象......”

  • 在这两种情况下,数据都不会共享,但是在单例中一次只能连接一次客户端,为什么有人想要这样
    在什么情况下单例有用,它们之间还有什么区别吗?

    最佳答案

    你看错了台词。这是 MSDN 上的定义。我突出显示(粗体)这些对象之间的一些差异。

    • Single Call

      Single Call objects service one and only one request coming in. Single Call objects are useful in scenarios where the objects are required to do a finite amount of work. Single Call objects are usually not required to store state information, and they cannot hold state information between method calls. However, Single Call objects can be configured in a load-balanced fashion.

    • Singleton Objects

      Singleton objects are those objects that service multiple clients and hence share data by storing state information between client invocations. They are useful in cases in which data needs to be shared explicitly between clients and also in which the overhead of creating and maintaining objects is substantial.

    • Client-Activated Objects (CAO)

      Client-activated objects (CAO) are server-side objects that are activated upon request from the client. This way of activating server objects is very similar to the classic COM coclass activation. When the client submits a request for a server object using "new" operator, an activation request message is sent to the remote application. The server then creates an instance of the requested class and returns an ObjRef back to the client application that invoked it. A proxy is then created on the client side using the ObjRef. The client's method calls will be executed on the proxy. Client-activated objects can store state information between method calls for its specific client and not across different client objects. Each invocation of "new" returns a proxy to an independent instance of the server type.



    状态信息是您存储在对象的变量或属性中的一些数据,用于处理客户端请求。

    单个调用对象在客户端请求它做一些工作时创建,并在它完成工作后销毁,它不能保存状态信息,导致每个请求创建一个新对象(它可以在数据源中加载和存储数据,以完成它的工作)。

    A 单例对象 仅创建一次(可能在服务器启动时)并且只要服务器进程正在运行就一直存在。它可以将信息存储在变量和属性中以处理客户端请求,使每个客户端都使用相同的对象,并且不会在客户端调用后销毁。

    显示单个调用和单例对象之间差异的一个简单示例是创建一个方法 Increment() 来增加对象中的变量(整数)并将变量写入控制台。单个调用对象将始终向控制台打印相同的值(如果变量以 0 开头,则为 1),而单例对象将始终在每次调用后打印一个递增的值(1、2、3 等)。

    关于.net - 单例和客户端激活对象(CAO),Remoitng,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3184067/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com