.NET Remoting: Using Interfaces


Using .NET Remoting and SoapSuds tools (SOAPSUDS.Exe) to extract metadata using Interface mechanism as an Alternative to SOAPSUDS. Explanation of concepts with examples of each.

Introduction

In the previous article we used Soapsuds to extract the metadata from the Remoting Server so that we don't need to deploy the complete implementation assembly to your clients.

Another alternative way is to use Interfaces to access remote objects instead of using SoapSuds.There are many articles available on the internet which discusses the pro's and Con's of Interfaces Vs Soapsuds.

Create the Interface dll
Create a Class library called Inter.


using System;
public interface IService
{
int Addition (int num1,int num2)
}

Creating the Server Application
Create a Class library called ServerApp which Implements the IService Interface

using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Http;
using System.IO;

namespace ServerApp
{
public class Service: MarshalByRefObject,IService
{
public int Addition (int num1,int num2)
{
return num1 + num2;
}
}
}


Steps to deploy this Server in IIS.

1. Create a new folder and we will call it as "RemotingSample".
2. Create another new folder called "bin" inside RemotingSample folder.
3. Place the ServerApp.dll inside the "bin" folder.
4. Place the following Web.Config file inside the RemotingSample folder.

<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall" objectUri="AdditionService.rem" type="ServerApp.Service, ServerApp"/>
</service>
<channels>
<channel ref="http"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>

5. Create a virtual directory in IIS.. say MyServer and map the path to the RemotingSample folder. You can test whether the Server is properly deployed by typing in

http://ServerName/MyServer/AdditionService.rem?wsdl

Client Application


The Distributed Inter.dll will be available to the Client.

1. Create a Windows Forms Application.
2. Add Reference to the Inter.dll in this application
3. Add a button and in the Button Click Event add the following Code :-

IService obj = (IService) Activator.GetObject(typeof(IService),"http://ServerName/MyServer/AdditionService.rem");
MessageBox.Show(obj.Addition(5,6).ToString());

4. In the form load add the follwing Code..

HttpChannel channel = new HttpChannel();
ChannelServices.RegisterChannel(channel);

Summary
This method will help you to use interface based remoting .
Srinu
U Can Reach me @ 9840063939


Comments

Author: Ravi Ranjan13 Sep 2004 Member Level: Silver   Points : 0

It is really a nice article. it is really helpful for learner.
Thankx to this.

Author: Sreenivasa Rao01 Oct 2004 Member Level: Silver   Points : 0

http://ServerName/MyServer/AdditionService.rem?wsdl
I have changed server name as localhost. I am getting The page cannot be displayed error. Please let me know what i have missed.

Author: Kaja Moinudeen01 Oct 2004 Member Level: Bronze   Points : 0

Keep up the good work.I expect a similar article on webservices from you.

Author: AGA31 Dec 2004 Member Level: Bronze   Points : 0

Dear Friend,

It is really a good article for the beginners.

Best Regards,

Avinash.

Author: shashi kant pathak07 Jul 2005 Member Level: Bronze   Points : 0

hi,
this is shashi kant pathak from delhi working as a senior programmer.
presently i am developing a software which require the remoting.
but i am completing it. i have study you article

in the web.config file there is a line



in which is am not under standing that what is additionServices.rem is it a external file or what?

Author: Suresh Raj07 Sep 2009 Member Level: Silver   Points : 1

hi,
In Steps to deploy this Server in IIS-- Step 3
don't we need to add Interface dll i.e inter in the bin folder ???

Regards,
Suresh



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: