gpt4 book ai didi

.net - 什么是真实透明代理

转载 作者:行者123 更新时间:2023-12-02 21:36:11 24 4
gpt4 key购买 nike

在 .NET 远程处理中,有两种代理:

  1. 透明代理
  2. 真实代理

它们有什么区别?

最佳答案

来自MSDN :

The TransparentProxy is an internal class that cannot be replaced orextended. On the other hand, the RealProxy and ObjRef classes arepublic and can be extended and customized when necessary. TheRealProxy class is an ideal candidate for performing load balancingfor example, since it handles all function calls on a remote object.When Invoke is called, a class derived from RealProxy can obtain loadinformation about servers on the network and route the call to anappropriate server. Simply request a MessageSink for the requiredObjectURI from the Channel and call SyncProcessMessage orAsyncProcessMessage to forward the call to the required remote object.When the call returns, the RealProxy automatically handles the returnparameter.

Here's a code snippet that shows how to use a derived RealProxy class.

MyRealProxy proxy = new MyRealProxy(typeof(Foo));
Foo obj = (Foo)proxy.GetTransparentProxy();
int result = obj.CallSomeMethod();

The TransparentProxy obtained above can be forwarded to anotherapplication domain. When the second client attempts to call a methodon the proxy, the remoting framework will attempt to create aninstance of MyRealProxy, and if the assembly is available, all callswill be routed through this instance. If the assembly is notavailable, calls will be routed through the default remotingRealProxy.

An ObjRef can easily be customized by providing replacements fordefault ObjRef properties TypeInfo, EnvoyInfo, and ChannelInfo. Thefollowing code shows how this can be done.

public class ObjRef {
public virtual IRemotingTypeInfo TypeInfo
{
get { return typeInfo;}
set { typeInfo = value;}
}

public virtual IEnvoyInfo EnvoyInfo
{
get { return envoyInfo;}
set { envoyInfo = value;}
}

public virtual IChannelInfo ChannelInfo
{
get { return channelInfo;}
set { channelInfo = value;}
}
}

关于.net - 什么是真实透明代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19244524/

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