Using Interfaces In .NET Remoting

Introduction

Abstract

.NET Remoting allows for a clean seperation between client side code and server side code through the use of interfaces. This allows a developer to distribute generic interfaces to client machines and change the server side code without having to redistribute the code changes back to the clients.

In this article, we will create a remote object and referance it only by interface. We will also create an interfaces DLL that both the client and server code use.

Step 1: Creating The Interface Library

Launch Visual Studio.NET, then choose File->New->Project. Choose to create a new "C# Library" and name it RemotingExampleInterfaces then click on OK. The purpose for this library is to declare the object interfaces that we will use on both the client and server side.

The code for this library is very simple, but a few notes need to be placed on the code below.

First, instead of declaring classes we are declaring interfaces. This tells the compiler that we're not actually creating a class, we are creating a "template" for a class. An interface defines what Methods the object should have as well as the parameters and return values for these methods. Note the ';' at the end of each method declaration instead of the '{}'s that would normally contain the method's implementation. The final thing to mention on interfaces as that they have no access modifiers such as public or private. That is defined by the class that we choose to implement our interface in.

using System;

namespace RemotingExampleInterfaces
{

	public interface IResume
	{
		String GetFormattedResume();
		String GetFormattedName();
	}

	public interface IRemotingExampleService
	{
		IResume GetResume();
		String GetFormattedResume();
	}
}

Choose Build from the Build menu to compile this DLL. The output will be placed in the bin/Debug subdirectory of you project directory.

You might also like...

Comments

About the author

David Talbot United States

David Talbot is an experienced Software Architect with a diverse background including creating network applicances, working with television set top boxes, building Billing/CRM systems, Web Port...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra