C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » WCF/Webservices »

.NET Remoting: Using Interfaces


Posted Date: 10 Sep 2004    Resource Type: Articles    Category: WCF/Webservices
Author: DotnetFreakMember Level: Silver    
Rating: 1 out of 5Points: 7



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




Responses

Author: Ravi Ranjan    13 Sep 2004Member Level: Silver   Points : 0
It is really a nice article. it is really helpful for learner.
Thankx to this.


Author: Sreenivasa Rao    01 Oct 2004Member 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 Moinudeen    01 Oct 2004Member Level: Bronze   Points : 0
Keep up the good work.I expect a similar article on webservices from you.


Author: AGA    31 Dec 2004Member Level: Bronze   Points : 0
Dear Friend,

It is really a good article for the beginners.

Best Regards,

Avinash.



Author: shashi kant pathak    07 Jul 2005Member 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 Raj    07 Sep 2009Member Level: Gold   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


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: .NET Remoting: Hosting the Server in IIS
Previous Resource: .Net Remoting
Return to Discussion Resource Index
Post New Resource
Category: WCF/Webservices


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use