Compartilhar via


Como: Compilação a Application Hosting

Por si só, a classe RemotableType definidos o como Para: Compilação um tópico Tipo Remotable não é especial. Para habilitar objetos em outros domínios aplicativo para criar instâncias deste objeto remotamente, é necessário Compilação um aplicativo hospedar ou ouvinte para fazer o seguinte itens:

  • Escolha e registre um canal, que é um objeto que trata os protocolos de rede e a serialização formatos em seu nome.

  • Registrar o seu tipo com o sistema do sistema de interação remota .NET para que ele possa usar o canal para ouvir solicitações para o seu tipo.

O .NET Framework inclui três canais padrão, HttpChannel (que usa SOAP formatação por padrão), TcpChannel (que usa formatação binário por padrão) e IpcChannel (que usa formatação binário por padrão). HttpChannel can be used through firewalls without opening a porta and it supports padrão Segurança and Protocols autenticação. Para obter mais informações sobre como escolher canais que atender seu cenário, consulte canais.

You can compilar ouvinte Applications Using any tipo of domínio do aplicativo — a aplicativo do Windows Forms, an aplicativo ASP.NET, a aplicativo console, a Windows Serviço (also Known as a Windows NT Serviço), or any Other gerenciado domínio do aplicativo. Because remoto configuração is for each domínio do aplicativo, must be the domínio do aplicativo Executando to escutar for requests.

Dica

Unlike COM, arquitetura de comunicação remota not iniciar the Host or for you aplicativo servidor.This is an important Difference between arquitetura de comunicação remota do.NET and Remoto ativação in COM.

Configuration can be programaticamente or by Using an aplicativo or Computador arquivo de configuração.

The sistema arquitetura de comunicação remota uses the informações in this arquivo to escutar for and rota Remoto requests to an instância of a tipo remoto. The arquivo specifies the servidor - modo ativação, the tipo Name and assembly of the tipo on behalf of which it is to escutar, and the objeto Uniform recurso Identifier (URI) or externo name of the objeto. (Para obter mais informações sobre o objeto URIs e sistema de interação remota, consulte URLs de ativação.)

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.

Using a enables you to the without recompiling Your Executável, among other things. Para obter informações sobre a configuração da infra-estrutura de .NET Remoting, consulte Esquema configurações Remoting.

Dica

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

Para implementar um domínio do aplicativo host simples que usa um arquivo de configuração

  1. Continuing on from the Como: Compilação a Type Remotable, Criar another under remoting and it host. Criar a for the . The aplicativo hospedar must be able to the configuração carregar for the Remoto classe, and therefore, the arquivo de configuração should be Saved in the same Diretório As assembly 's aplicativo host the, or it is not found and is an exceção thrown. O código a seguir mostra um arquivo de configuração que especifica o objeto remoto é um singleton, sua implementação é uma classe chamada RemotableType localizado em um conjunto de módulos (assembly) denominado RemotableType. Avançar, um HttpChannel está registrado escutando na porta 8989. Salvar This arquivo in the Diretório remoting\listener. O nome do arquivo deve seguir o padrão de App-Name. exe.config. Neste maiúscminúsc é chamado listener.exe.config.

    <configuration>
       <system.runtime.remoting>
          <application>
             <service>
                <wellknown 
                   mode="Singleton" 
                   type="RemotableType, RemotableType" 
                   objectUri="RemotableType.rem"
                />
             </service>
             <channels>
                <channel ref="http" port="8989"/>
             </channels>
          </application>
       </system.runtime.remoting>
    </configuration>
    
  2. Criar um novo arquivo de origem para o idioma de escolha. At the parte superior of the arquivo origem Importar the namespace System.Runtime.Remoting:

    Imports System
    Imports System.Runtime.Remoting
    
    using System;
    using System.Runtime.Remoting;
    
  3. In the Main, the that configures the , a letting the know the Host is , and then wait for a . Salvar This arquivo in the Diretório remoting\listener.

    Public Class Listener
        Public Shared Sub Main()
            RemotingConfiguration.Configure("Listener.exe.config", False)
            Console.WriteLine("Listening for requests. Press enter to exit...")
            Console.ReadLine()
        End Sub
    End Class
    public class Listener
    {
        public static void Main()
        {
            RemotingConfiguration.Configure("Listener.exe.config", false);
            Console.WriteLine("Listening for requests. Press enter to exit...");
            Console.ReadLine();
        }
    
    }
    
  4. Copiar the generated in Como: Compilação a Type Remotable into the Diretório remoting\listener RemotableType.dll. O aplicativo host deve fazer referência neste conjunto de módulos (assembly). Compile this classe into an Executable by the seguinte typing Comando:

    vbc /r:RemotableType.dll Listener.vb
    csc /noconfig /r:RemotableType.dll Listener.cs
    
  5. Agora você tem um conjunto de módulos (assembly) denominado Listener.exe. Try Executando Now it to see if the configuração succeeds. Uma caixa de diálogo de segurança pode ser exibida se um firewall está bloqueando a porta 8989 no momento. Caso clique no botão "desbloquear" para abrir temporariamente o firewall nessa porta.

  6. Para obter informações adicionais sobre como usar o tipo remotable, consulte Como: Compilação a Application Client.

Exemplo

' Listener.vb
Public Class Listener
    Public Shared Sub Main()
        RemotingConfiguration.Configure("Listener.exe.config", False)
        Console.WriteLine("Listening for requests. Press enter to exit...")
        Console.ReadLine()
    End Sub
End Class
// Listener.cs
using System;
using System.Runtime.Remoting;

public class Listener
{
    public static void Main(string[] args)
    {
        RemotingConfiguration.Configure("Listener.exe.config", false);
        Console.WriteLine("Listening for requests. Press enter to exit...");
        Console.ReadLine();
    }
}

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