Showing posts with label .Net Remoting. Show all posts
Showing posts with label .Net Remoting. Show all posts

Tuesday, 3 May 2011

Asp.net Remote objects

Asp.net Remote objects:

Any object outside the application domain of the caller application should be considered remote
Remote objects are accessed through Channels ,two existing channels TcpChannel and HttpChannel

Types of .Net remotable objects
  • Single Call=Single Call objects service one and only one request coming in.
  • Single Call objects are usually not required to store state information.
  • Singleton Objects =Singleton objects are those objects that service multiple clients, and hence share data by storing state information between client invocations
  • Client Activated Objects are server-side objects that are activated upon request from
    client . When the client submits a request for a server object using a "new" operator, an activation request message is sent to the remote application. The server then creates an instance of the requested class, and returns an ObjRef back to the client application that invoked it

Thursday, 27 January 2011

Example code For .Net Remoting

create class library name as Sample Object using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace CodeGuru.Remoting
public class SampleObject : MarshalByRefObject
{
public SampleObject() // Constructor
{
}public string HelloWorld() // return string{return "Hello World!";}}} Create a Server To Expose the Remotable Object Create a new C# console application project. Add a class called SampleServer
namespace CodeGuru.Remoting
{
public class SampleServer
{
public static int Main(string [] args)
{
TcpChannel channel = new TcpChannel(8080);// Create an instance of a channel
ChannelServices.RegisterChannel(channel);

//Register as an available service with the name HelloWorld
RemotingConfiguration.RegisterWellKnownServiceType
(typeof(SampleObject), "HelloWorld", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Press the enter key to exit...");
System.Console.ReadLine();
return 0;
}
}}

Create a Client To Use the Remotable Object


public class SampleClient
{
public static int Main(string [] args)
{
// Create a channel for communicating w/ the remote object
// Notice no port is specified on the clientTcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
// Create an instance of the remote object
SampleObject obj = (SampleObject) Activator.GetObject
(typeof(CodeGuru.Remoting.SampleObject),"tcp://localhost:8080/HelloWorld" );
// Use the object
if( obj.Equals(null) )
{
System.Console.WriteLine("Error: unable to locate server");
}
else
{
Console.WriteLine(obj.HelloWorld());
}
return 0;
}
Create a new C# console application project. Add a class called SampleClient

Difference Between WebService and .Net Remoting


  • ASP.NET based Web services can only be accessed over HTTP.
  • .NET Remoting can be used across any protocol. (TCP.Http)
  • Web services work in a stateless environment where each request results in a new object created to service the request.
  • .NET Remoting supports state management options and can correlate multiple calls from the same client and support callbacks.Web services are easy to create and use while .NET Remoting are complex  to be created
  • Web services serialize objects through XML contained in the SOAP messages and can thus only handle items that can be fully expressed in XML.
  • .NET Remoting relies on the existence of the common language runtime assemblies that contain information about data types. This limits the information that must be passed about an object and allows objects to be passed by value or by reference.
  • Web services support interoperability across platforms and are good for heterogeneous environments.
  • .NET Remoting requires the clients be built using .NET, or another framework that supports .NET Remoting, which means a homogeneous environment.

Remote objects:

Asp.net Remote objects:

Any object outside the application domain of the caller application should be considered remote
Remote objects are accessed through Channels ,two existing channels TcpChannel and HttpChannel

Types of .Net remotable objects
  • Single Call=Single Call objects service one and only one request coming in.
  • Single Call objects are usually not required to store state information.
  • Singleton Objects =Singleton objects are those objects that service multiple clients, and hence share data by storing state information between client invocations
  • Client Activated Objects are server-side objects that are activated upon request from
    client . When the client submits a request for a server object using a "new" operator, an activation request message is sent to the remote application. The server then creates an instance of the requested class, and returns an ObjRef back to the client application that invoked it

What is .NET Remoting?

  •  .NET Remoting is a mechanism for communicating between objects which are not in the same process. It is a generic system for different applications to communicate with one another. .NET objects are exposed to remote processes, thus allowing inter process communication. The applications can be located on the same computer, different computers on the same network, or on computers across separate networks.

  • Inter process communication between application was handled through Distributed COM.

  • .Net Remoting eliminates the difficulties of DCOM by supporting different transport protocol formats and communication protocols