Server-activated Remote Object Client Sample: Hosted in a Custom Application

Whenever a Web service or a remote object is generated, a configuration file is also created. Below is a sample of a simple task execution using a server-actived remote object hosted in a custom application and a sample configuration file.

using System;
using System.Runtime.Remoting;

namespace CSharpClient
{
	/// <summary>
	/// A simple console application that demonstrates how to execute a task
	/// via a server-activated remote singleton.  This project references
	/// a generated assembly called Test.dll.  The remote component is hosted
	/// in a custom application that listens on TCP port 8989.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			Test.RemoteTest remoteTest = null;

			try
			{
				//Configure RemoteTestFactory as a server-activated object
				RemotingConfiguration.Configure("RemoteTestClient.config");

				//Use the remote factory to instantiate RemoteTest
				remoteTest = new Test.RemoteTestFactory().createRemoteTest();

				//Prepare the remote object for stateful execution
				remoteTest.open();
				
				//Set the task inputs
				Test.Task1Input.Task1ScreenInputs inputs = new Test.Task1Input.Task1ScreenInputs();
				inputs.Input1 = "data";

				//Execute the task
				Test.Task1Output.Task1ScreenOutputs outputs = remoteTest.Task1(inputs);

				//Display the output
				System.Console.WriteLine(outputs.Output1);
			}
			catch (Exception xx)
			{
				System.Console.Error.WriteLine(xx);
			}
			finally
			{
				//Clean up
				remoteTest.close();
			}
		}
	}
}

Sample Configuration File for Server-activated RemoteTestClient.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.runtime.remoting>
<!-- Configuration for a server-activated RemoteTestFactory singleton
 - hosted in a custom application. -->
<application>					
<client>
<wellknown type="Test.RemoteTestFactory, Test" url="tcp://localhost:8989/Test"/>
</client>
<channels>
<channel ref="tcp">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
</channel>>
</channels>
</application>	
</system.runtime.remoting>
</configuration>
Related Topics
Bullet Using Tasks in Your Applications, Overview
Bullet Using .NET
  Attachmate