.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Remoting >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Two Ways to invoke Remote Method ( Object )

Posted By:Muthu       Posted Date: November 02, 2010    Points: 15    Category: Remoting    URL: http://www.dotnetspark.com  

There are two ways to invoke a remote method 1)Well Known Object Activation (WKO) 2)Client Activation Object (CAO)
 

 

The following is an example for the object creation and activation is Well Known Object

Activation (WKO)

1. Creating an interface

namespace RemoteInterface
{
 public interface IDisp
 {
  void disp();
 }
}

2. Creation of the server


using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using RemoteInterface;
namespace RemotingServer
{
 // server object implementation

 public class dipsplay : MarshallByRefObject,IDisp
 {
  public display()
  {
   Console.WriteLine("From the Server");
  }

  public void disp()
  {
   Console.WriteLine("server Invoked");
  }
 }

//Implementing Host

 class Program
 {
  static void Main()
  {
   // creation of the channel for communication

   HttpChannel ch=new httpChannel(65000);
   ChannelServices.RegisterChannel(ch,false);

   // registering the services at the endpoint

 RemotingConfiguration.RegisterWellKnownServiceType(typeof

(Display),"DisplayService",WellKnownObjectMode.SingleCall);
  }
 }
}

 


3.   Creation of client


using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using RemoteInterface;
namespace RemoteClient
{
 class Program
 {
  static void Main()
  {
   // create a channel

   HttpChannel ch=new httpChannel(0);

// transperent proxy  

   MarshallByRefObject obj=new (MarshallByRefObject)

remotingServices.Connect(typeof(IDisp),"http://localhost:65000/DisplayService");  

   IDisp  d=obj.Disp();
  }
 }
}


On execution the o/p is:

From the Server
server Invoked


 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend