.NET Remote Client Object Sample Code: Server-activated Server

A simple console application that demonstrates how to host a server-activated remote object. This application listens for client requests on TCP port 8989. Whenever a Web service or a remote object is generated, a configuration file is also created. Below is a sample of a custom host application using a server-activated remote object and a sample configuration file.

using System;
using System.Runtime.Remoting;

// NOTE: Add project referenct to IVTNO.DLL
// 1. Project \ Add Reference... menu item
// 2. Use Browse button to find and add DLL.
using IVTNO;

namespace IVTNORemoteClient
{
  /// <summary>
  /// Summary description for Class1.
  /// </summary>
  class Class1
  {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
      IVTNO.RemoteIVTNO remoteIVTNO = null;

      try
      {
        //Configure RemoteIVTNO as a server-activated object 
        RemotingConfiguration.Configure("C:\\Program Files\\Attachmate\\EAI\\IMSClient\\samples\\IVTNO\\remote\\IVTNO\\RemoteIVTNOClient.config");

        //Instantiate the remote object
        remoteIVTNO = new IVTNO.RemoteIVTNOFactory().createIVTNO();

        //Prepare the remote object for stateless execution
        remoteIVTNO.open();
                    
        //Set the task inputs
        IVTNO.IVTNOInput.input input = new IVTNO.IVTNOInput.input();

        input.INPUT_RCD = new IVTNO.IVTNOInput.input_INPUT_RCD();
        input.INPUT_RCD.IN_TRNCODE   = "IVTNO";
        input.INPUT_RCD.IN_CMD   = "DISPLAY";
        input.INPUT_RCD.IN_LASTNAME = "LAST1";
        input.INPUT_RCD.IN_FIRSTNAME = "";
        input.INPUT_RCD.IN_EXTN = "";
        input.INPUT_RCD.IN_ZIP = "";

        //Execute the task
        IVTNO.IVTNOOutput.output output = remoteIVTNO.IVTNO(input);

        //Display the output
        System.Console.WriteLine(output.OUTPUT_RCD.OUT_MSG);
        System.Console.WriteLine(output.OUTPUT_RCD.OUT_CMD);
        System.Console.WriteLine(output.OUTPUT_RCD.OUT_LASTNAME);
        System.Console.WriteLine(output.OUTPUT_RCD.OUT_FIRSTNAME);
        System.Console.WriteLine(output.OUTPUT_RCD.OUT_EXTN);
        System.Console.WriteLine(output.OUTPUT_RCD.OUT_ZIP);
      }
      catch (Exception xx)
      {
        System.Console.Error.WriteLine(xx);
      }
        finally
      {
        //Clean up
        if ( remoteIVTNO != null )
          remoteIVTNO.close();
      }		
    }
  }
}

Sample Configuration File: RemoteIVTNOClient.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.runtime.remoting>
<!-- Configuration for a server-activated RemoteIVTNOFactory singleton
 - hosted in a custom application.-->
 <application>        
<client>
<wellknown type="IVTNO.RemoteIVTNOFactory, IVTNO" url="tcp://localhost:8989/IVTNO"/>
</client>
<channels>
<channel ref="tcp">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Related Topics
Bullet Using .NET
Bullet Adding .NET Remotable Objects to .NET Projects
Bullet .NET Deployment Examples
  Attachmate