Compartilhar via


Como: Compilação a Application Client

To compilar a cliente of the remoto tipo defined in Como: Compilação a Type Remotable and Hosted by the aplicativo Criado in Building a Host Application, Your aplicativo must registrar itself as a cliente for that remoto objeto and then invocar IT as though IT were within domínio do aplicativo the cliente 's. The intercepts sistema de comunicação remota do.NET Your cliente Calls, forwards them to the Remoto objeto, and returns the results to Your cliente. The seguinte procedimento describes How to Compilação a cliente Basic arquitetura de comunicação remota.

Dica

See Como: Compilar and Run a Application Remoting Basic for completo Instructions on How to Compilação and executar this exemplo.

To Compilação a Basic

  1. Continuando a partir Como: Compilação a Application Hosting, criar um Novo Diretório em chamado remotingclient. Create a arquivo de configuração for the aplicativo cliente as shown in the seguinte Código salvar and the arquivo in the Diretório remoting\client. O Nome do Arquivo deve seguir o padrão de App-Name. exe.config. Neste maiúscminúsc, é chamado client.exe.config. The seguinte arquivo de configuração tells the sistema arquitetura de comunicação remota that the Informações do tipo for the remoto RemotableType objeto can be found in the assembly RemotableType and the objeto is located at https://localhost:8989/RemotableType.rem.

    <configuration>
       <system.runtime.remoting>
          <application>
             <client>
                <wellknown 
                   type="RemotableType, RemotableType"
                   url="https://localhost:8989/RemotableType.rem"
                />
             </client>
          </application>
       </system.runtime.remoting>
    </configuration>
    

    Para obter detalhes sobre o atributo URL neste arquivo de configuração, consulte URLs de ativação. Se você deseja executar este aplicativo através de uma rede, você deve substituir localhost na configuração do cliente com o nome do computador remoto.

    Dica

    Embora haja apenas algumas configurações no arquivo de configuração anterior, a maioria dos problemas usando sistema de interação remota .NET ocorre porque algumas dessas configurações são um incorreto ou não correspondam as definições de configuração de aplicativos cliente.É fácil digitar um nome errado, esquecer uma porta ou não um atributo.If you are HAVING Problems with Your aplicativo arquitetura de comunicação remota, verificar Your Settings configuração Primeiro.

  2. Criar um novo arquivo de origem no idioma de sua escolha. No método principal, chamada RemotingConfiguration.Configure passando no nome do arquivo de configuração do cliente (client.exe.config). Avançar, criar instância an instância of RemotableType and chamar its método SayHello. Salvar The aplicativo cliente as Client.cs or Client.vb in the Diretório remoting\client.

    Dica

    O aplicativo cliente não deve ser salvo na mesma Diretório de seu aplicativo Listener.exe.If it is, You Cannot Be Certain that you are receiving and making Use of a Remoto Reference, because resolução assembly and tipo can ocorrer When Applications are in the same Diretório.

       Public Shared Sub Main()
          RemotingConfiguration.Configure("Client.exe.config")
          Dim remoteObject As New RemotableType()
          Console.WriteLine(remoteObject.SayHello())
       End Sub 'Main
    
       public static void Main(){
          RemotingConfiguration.Configure("Client.exe.config");
          RemotableType remoteObject = new RemotableType();
          Console.WriteLine(remoteObject.SayHello());
       }
    
  3. Copiar The assembly from remoting\Type RemotableType.dll into remoting\client.

    Dica

    Uma pergunta comum nesse momento é "Como posso saber se o objeto remoto obtém chamado se eu estou copiar o conjunto de módulos (assembly) para o cliente?" This is exactly Why We Adicionado the chamar to Console.WriteLine in the método RemotableType.SayHello().Se o objeto remoto está sendo chamado o WriteLine ocorre no processo de escuta, se não o WriteLine ocorre no processo do cliente.

  4. Compilar aplicativo cliente, digitando o seguinte Comando no Diretório remoting\client:

    vbc /r:RemotableType.dll Client.vb
    csc /noconfig /r:RemotableType.dll Client.cs
    
  5. Abrir até dois prompts de comando. Em um, Ir para o Diretório remoting\listener e executar Listener.exe. No outro, vá para o remoting\ Cliente Diretório e executar Cliente.exe. O comando cliente-prompt deve aspecto como este:

    C:\tmp\Remoting\client>client 
    Hello, world 
    
  6. O ouvinte de prompt de comando deve ter esta aparência:

    C:\tmp\Remoting\listener>listener
    Listening for requests. Press Enter to exit...
    RemotableType.SayHello() was called!
    
  7. Você pode ver, a saída de escuta que ele recebeu uma chamada para RemotableType.SayHello().

Exemplo

' Client.vb 
Imports System
Imports System.Runtime.Remoting

Public Class Client
   Public Shared Sub Main()
      RemotingConfiguration.Configure("Client.exe.config")
      Dim remoteObject As New RemotableType()
      Console.WriteLine(remoteObject.SayHello())
   End Sub 'Main
End Class 'Client
// Client.cs 
using System;
using System.Runtime.Remoting;

public class Client{

   public static void Main(){
      RemotingConfiguration.Configure("Client.exe.config");
      RemotableType remoteObject = new RemotableType();
      Console.WriteLine(remoteObject.SayHello());
   }
}

Consulte também

Tarefas

Como: Compilação a Application Hosting

Conceitos

Configuração de aplicativos remoto

A ativação do servidor

Outros recursos

Criando um aplicativo do Sistema de Interação Remota Basic .NET Framework

Esquema configurações Remoting