.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
It is really a nice article. it is really helpful for learner.
Thankx to this.