Library tutorials & articles
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.
Related articles
Related discussion
-
True multithread VB source code controls
by Un1 (2 replies)
-
Visual Studio.NET Beta 2 CD
by gringod (2 replies)
-
VB HELP!!!!!!!!!
by CodeWarrior76 (3 replies)
-
EXE Decompiler ?
by James Crowley (6 replies)
-
When is it released?
by outvit (5 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Medior/Senior Microsoft .NET Developer
in Randstad en Omstreken (€3K-€4K per month) -
Key Accountmanager
in Noord Holland (€40K-€50K per annum)
Events coming up
-
Oct
14
What’s New in Visual Studio 2008 Service Pack 1?
Birmingham, United Kingdom
“Service Pack? We’re calling it a Service Pack? Are you kidding??!?!” Visual Studio 2008 Service Pack 1 will release later in 2008 alongside .NET Framework V3.5 Service Pack 1 and, together, they represent a significant upgrade to Visual Studio 2008. There are enhancements across many areas of the .NET Framework such as data access, windows application development and web development and there are also corresponding changes in the development environment to support the new framework features.
Hi,
I too have the same problem. Did you find any solution for that?
Regards
Paul
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:
-----------------------------------VB Code------------------------------------------------------------
Sub Main()
ChannelServices.RegisterChannel(New HttpChannel())
Dim factory As RemotingClientsInterfaces.IAccountantExamFactory 'this is the object Im tring to remote
'this is the line where the excaption accure
factory = CType(Activator.GetObject( _
Type.GetType("RemotingClientsInterfaces.IAccountantExamFactory"), _
"http://10.0.0.172:8080/IExamFactory"), RemotingClientsInterfaces.IAccountantExamFactory)
.
.
.
---------------------------end of Code-------------------------------------------------------------------
See anything suspicious ???
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 caveats when using different languages). So basically, when calling the VB.NET methods, ensure you provide all parameters including the "Optional" ones.
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 VB.NET and got an exception while trying to create the remote object:
"An unhandled exception of
type 'System.ArgumentNullException' occurred in
mscorlib.dll
Additional information: Value cannot be null."
do you have any suggestions what so ever ???
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.
Can I use remoting when the server is written in C# and the client in VB.NET ? If so does any one knows where I can find an example for this?
My E-Mail: assaf@nipendo.com
Thanks
Well the article describes very well how to use .NET Remoting in your application.But does not give a good comparision with widely used remoting procedure i,e DCOM.
Unless a developer get the comparision between two technologies he/she may not choose the new one.
Ghanshyam.
Hello, I would like to remote an interface to a client-activated object. This sample, and others I've seen assume a singleton/single-use object, which won't work for my application. Or, is there no way to do CAO's with interfaces? Help! Thank you.
Hi,
Can you please pass me the Client application source code for your article .Net Remoting. I think you forgot to upload in your site at http://www.developerfusion.com/show/2082/3/
Can you please forward the source code to my e-mail ID @ r_nazermd@yahoo.com
Thanks and Regards
Nazer Mohamed
Good article. The client side code was missing until I went to the printer friendly version. I ran the code and it worked as expected.
I have a couple of questions about interfaces. Is it possible to initialize a type "such as byte [] array" within the main program and allow the interfaces to access that initialized type so that the clients could do something with it? I thought that the use of interfaces would be a good tool for clients to use to get information from a server that is constantly polling external data. The only examples that I have seen so far, show me that the main thread is completely separate from the interfaces. Is this true?
Tom McDaniel