Share via


Estendendo RealProxy

Extending the proxy can be useful When You desejar to participate in the processo Creation proxy, remoto empacotar método Calls, or determine objeto identidade, among Outro Things. Você pode Compilação seu próprios proxy usando o extensível https://msdn.microsoft.com/pt-br/library/f59atft6(v=vs.85) RealProxy classe. To build a custom proxy involves deriving a class from the RealProxyclass and overriding the RealProxy.Invoke method. The new (Newin Visual Basic) statement can be intercepted by deriving from the ProxyAttribute attribute and applying the attribute to a child of ContextBoundObject. (Applying the atributo proxy to a filho of MarshalByRefObject não é com suporte.) When new is the derivado, chamado ProxyAttribute CREATES an instância of the Personalizar proxy. An aplicativo can also Criar a personalizado directly instância proxy.

When the código do aplicativo Calls a método on a Personalizar is the overridden RealProxy.Invoke método proxy, chamado with an objeto that Implements IMessage. The IMessageimplementation provides an IDictionary implementation that provides name/value pairs of information about the method. Para obter mais informações sobre determinadas entradas no dicionário, consulte a documentação de referência para a interface https://msdn.microsoft.com/pt-br/library/5c8cd72b(v=vs.85) IMessage e interfaces relacionadas (IMethodCallMessage e IMethodReturnMessage).

Um objeto real pode ser chamado a partir de método substituído Invoke chamando RemotingServices.ExecuteMessage, que distribui a chamada para o objeto real.

Also You can use the método EnterpriseServicesHelper.CreateConstructionReturnMessage to Processo an objeto IConstructionCallMessage and Generate an objeto IConstructionReturnMessage. Você também pode usar o https://msdn.microsoft.com/pt-br/library/sabzzhe5(v=vs.85) RealProxy.InitializeServerObject método para criar o objeto de backup (o objeto representado pelo proxy).

When Using the derivado ProxyAttribute, you can Criar a objeto real in the método overridden ProxyAttribute.CreateInstance and armazenar IT as a campo in the personalizado proxy. The personalizado proxy can empacotar the objeto real to Obtain the objeto ObjRef that contains the recurso Identifier Uniform (URI). The URI must be stored in the proxy, because the entrada "__Uri" in the coleção returned by the IMessage.Propriedades propriedade must be set in the implementação IMessage to distribuir a chamar to a objeto real.

Naturalmente, a mensagem não precisa ser distribuído em um objeto real; Você pode executar algumas tarefas com ele no Invoke e gerar e retornar um objeto que implementa o IMethodReturnMessage) Interface.

To participate in marshaling, override RealProxy.CreateObjRef and provide a custom ObjRefthat extends ObjRef. If you want to add custom data to the custom ObjRef, overrideObjRef.GetObjectData. Você adicionar seu personalizado dados e delegate para o método ObjRef.GetObjectData para modificar os recursos identidade objeto do arquitetura de comunicação remota do.NET sistema empacotamento.

During desserialização, the arquitetura de comunicação remota Sistema Calls Your overridden IObjectReference.GetRealObject on the personalizado ObjRef. aqui, you should delegado to the método GetRealObject()https://msdn.microsoft.com/pt-br/library/hdk41607(v=vs.85) de base because the de base Handles the identidade objeto and Sets up channels arquitetura de comunicação remota. Also the de base Calls Your overridden ProxyAttribute.CreateProxy método to Allow you to Set Up Your Personalizar proxy.

ObjRef.IsFromThisAppDomain e ObjRef.IsFromThisProcess podem ser usados para determinar como deseja desempacotar.

Anotação that If You do not Provide a personalizado the sistema arquitetura de comunicação remota, ObjRef During empacotamento automaticamente marshals and unmarshals the objeto and the personalizado proxy is used not in domínio do aplicativo the chamador 's.

Consulte também

Tarefas

Exemplo de tecnologia proxies Personalizars

Referência

RealProxy

ProxyAttribute

RemotingServices

IMessage

IMethodReturnMessage

IMethodCallMessage

Outros recursos

O sistema de interação remota avançado