Parse cross-application domain access of. NET objects (part II), and. net

Source: Internet
Author: User

Parse cross-application domain access of. NET objects (part II), and. net

In a twinkling of an eye, the Lantern Festival is just like a busy figure. In the new year, we should try our best to make ourselves have different lives and pursuits. Life is endless. In the previous blog, I mainly introduced the AppDomain information of. NET. In this blog, I will mainly describe the. NET assembly, object proxy, and the principle of object sending.

I. Assembly parsing:

When talking about Assembly, we need to know what assembly is. Let's look at the definition of assembly. An assembly can be roughly divided into two types: Class Libraries (The. DLL file we see) and executable programs (the. EXE file we see ). An assembly is a logical group of one or more modules/resource files (one module becomes a single Module assembly or a single file assembly; multiple modules become multi-module assembly or multi-file assembly ); an assembly is the minimum unit for reuse, security, and version control. The main component of the assembly, see the figure below:

Public virtual object GetTransparentProxy () {return this. _ tp ;}

In the namespace of System. Runtime. Remoting. Proxies, The RealProxy class provides basic proxy functions.

(2). ProxyAttribute. CreateProxy (): creates an instance of the remote processing proxy for the remote object described by the specified ObjRef and located on the server.

[SecurityCritical]    public virtual RealProxy CreateProxy(ObjRef objRef, Type serverType, object serverObject, Context serverContext)    {      RemotingProxy remotingProxy = new RemotingProxy(serverType);      if (serverContext != null)        RealProxy.SetStubData((RealProxy) remotingProxy, (object) serverContext.InternalContextID);      if (objRef != null && objRef.GetServerIdentity().IsAllocated)        remotingProxy.SetSrvInfo(objRef.GetServerIdentity(), objRef.GetDomainID());      remotingProxy.Initialized = true;      Type type = serverType;      if (!type.IsContextful && !type.IsMarshalByRef && serverContext != null)        throw new RemotingException(Environment.GetResourceString("Remoting_Activation_MBR_ProxyAttribute"));      return (RealProxy) remotingProxy;    }

In the namespace of System. Runtime. Remoting. Proxies, The ProxyAttribute class indicates that the object type requires a custom proxy. This method receives five parameters, objRef: Reference to the remote object for which a proxy is to be created; serverType: Type of the server where the remote object is located; serverObject: Server Object; serverContext: the context of the server object. The new instance of the Remote Object Remote Processing proxy described in the specified <see cref = "T: System. Runtime. Remoting. ObjRef"/>.

(3). RemotingServices: provides multiple methods to use and publish remote objects and proxies. This class cannot be inherited.

The GetRealProxy () method returns the real proxy after the specified transparent proxy.

 [SecurityCritical]    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]    [MethodImpl(MethodImplOptions.InternalCall)]    public static extern RealProxy GetRealProxy(object proxy);

This method receives parameters. proxy: a transparent proxy. This method returns the real proxy instance after the transparent proxy.

The IsTransparentProxy () method returns a Boolean value indicating whether the given object is a transparent proxy or an actual object.

[SecuritySafeCritical]    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]    [MethodImpl(MethodImplOptions.InternalCall)]    public static extern bool IsTransparentProxy(object proxy);

This method receives a parameter. proxy: The parameter references the object to be checked. This method returns whether the specified object is a transparent proxy or an actual object.

ExecuteMessage (): connect to the specified remote object and run the <see cref = "T: System. Runtime. Remoting. Messaging. IMethodCallMessage"/> provided for it.

  [SecurityCritical]    public static IMethodReturnMessage ExecuteMessage(MarshalByRefObject target, IMethodCallMessage reqMsg)    {      if (target == null)        throw new ArgumentNullException("target");      RealProxy realProxy = RemotingServices.GetRealProxy((object) target);      if (realProxy is RemotingProxy && !realProxy.DoContextsMatch())        throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_WrongContext"));      return (IMethodReturnMessage) new StackBuilderSink(target).SyncProcessMessage((IMessage) reqMsg);    }

This method receives two parameters, target: the remote object to call. ReqMsg: Specifies the method call message of the remote object method. This method creates a stack generator for the target object and sends a message to the receiver. The stack generator receiver processes the underlying stack operations and calls the actual method. When the method ends, the stack generator receiver converts the stack frame as the result to the response message, and the CLR uses it to return the result of the method call.

Iii. DotNet object sending and parsing:

The proxy is introduced above. Next we will briefly introduce the object delivery. There are two types of object delivery, one is to pass the value and the other is to pass the reference.

1. Pass value messages:

When an object in application A domain is passed to application B ,.. NET replicates and serializes the status of objects in A, re-creates the object in B, and accesses the object through the proxy object.

(1) (2) (2)

2. Pass the reference and mail:

Shows the structure of sending and passing references. When the client calls a method, the proxy sends a request to the remote object and the remote object executes the Method Request, finally, return the result to the client. This method is called sending a reference. There are three different methods for sending and passing reference messages: Client activation, Server activation Singleton, and Server activation SingleCall ). Three methods of common features, service objects are created and kept in the Host application.

Here we will not detail the method of sending and passing references.

Iv. Summary:

The cross-application domain method of objects is described so much and I hope it will be helpful to you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.