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.
Comments