Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 37,109 times

Contents

Related Categories

Using Interfaces In .NET Remoting - Introduction

David Talbot

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.

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 Portals and more. He has also provided technical guidance in different capacities on two C# books. David is currently finishing up work on a real estate analytics application in C# for Pathfinder Technologies and seeking additional contract or permenet work.

Comments

  • Posted by PaulLeo on 24 May 2004

    Hi,

    I too have the same problem. Did you find any solution for that?

    Regards
    Paul

  • re:

    Posted by asafsn on 28 May 2003

    Thanks again but I'm sorry to say I'm still not even in the stage you described in your reply of using a method of the remote object. I'm getting this exception in the following line:

    -------------...

  • Posted by James Crowley on 28 May 2003

    You may well find that is due to the use of the "Optional" keyword in VB.NET with a default value, rather than overloading the methods. Default values are not supported in C#. (... there are a few cav...

  • Re: C# and VB remoting

    Posted by asafsn on 28 May 2003

    thanks for the reply.

    Its time for me to be more specific.

    I wrote a server client application in C# using remoting
    and it worked. Then I replaced the client with another
    clients written in...

  • Posted by James Crowley on 28 May 2003

    I can certainly say that it is possible - the great thing with .NET is its ability to not care what .NET language you write any components in.... but I haven't got any examples, I'm afraid.