Sunday, November 30, 2008

.Net Remoting Interview Questions

  • What is .NET Remoting?

Net remoting replaces DCOM. Web Services that uses remoting can run in any Application type i.e. Console Application, Windows Form Applications, Window Services etc. In CLR Object Remoting we can call objects across network.

  • .NET Remoting Architecture?
  1. Methods that will be called from the client are implemented in a remote object class.
  2. Client uses a proxy to call a remote object.
  3. Remote objects runs inside a process that is different from the client process
  4. For the client, the proxy looks like the real object with the same public methods.
  5. When the methods of the proxy are called, messages are created.
  6. Messages are serialized using a binary formatter class, and are sent into a client channel.
  7. The client channel communicates with the server part of the channel to transfer the message across the network.
  8. The server channel uses a formatter to deserialize the message, so that the methods can be dispatched to the remote object.
  9. The formatter and the proxy is supplied automatically.
  • What is a formatter?

A formatter is an object that is responsible for encoding and serializing data into messages on one end, and deserializing and decoding messages into data on the other end.

  • How does .NET Remoting work?

.NET remoting involves sending messages along channels. Two of the standard channels are HTTP and TCP. TCP is intended for LANs only - HTTP can be used for LANs or WANs (internet).

Support is provided for multiple message serializarion formats. Examples are SOAP (XML-based) and binary. By default, the HTTP channel uses SOAP (via the .NET runtime Serialization SOAP Formatter), and the TCP channel uses binary (via the .NET runtime Serialization Binary Formatter). But either channel can use either serialization format.

There are a number of styles of remote access:

SingleCall:
Each incoming request from a client is serviced by a new object. The object is thrown away when the request has finished. This (essentially stateless) model can be made stateful in the ASP.NET environment by using the ASP.NET state service to store application or session state.

Singleton:
All incoming requests from clients are processed by a single server object.

Client-activated object:
This is the old stateful (D)COM model whereby the client receives a reference to the remote object and holds that reference (thus keeping the remote object alive) until it is finished with it.

  • What’s Singleton activation mode?

A single object is instantiated regardless of the number of clients accessing it. Lifetime of this object is determined by lifetime lease.

  • What’s SingleCall activation mode used for?

If the server object is instantiated for responding to just one single request, the request should be made in SingleCall mode.

  • .NET Remoting Specific Advantage?

Lease-Based Lifetime :

Distributed garbage collection of objects is managed by a system called 'leased based lifetime'. Each object has a lease time, and when that time expires the object is disconnected from the .NET runtime remoting infrastructure

.Net Remoting takes a Lease-base Lifetime of the object that is scaleable

Call Context :

Additional information can be passed with every method call that is not part of the argument with the help of SOAP Header

Distributed Identities :

If we pass a reference to a remote object, we will access the same object using this reference.

  • How do you define the lease of the object?

By implementing ILease interface when writing the class code.

  • What are channels in .NET Remoting?

Channels represent the objects that transfer the other serialized objects from one application domain to another and from one computer to another, as well as one process to another on the same box. A channel must exist before an object can be transferred.

  • How can you automatically generate interface for the remotable object in .NET with Microsoft tools?

Use the Soapsuds tool.

  • What are possible implementations of distributed applications in .NET?

.NET Remoting and ASP.NET Web Services. If we talk about the Framework Class Library, noteworthy classes are in System.Runtime.Remoting and System.Web.Services.

  • When would you use .NET Remoting and when Web services?

Use remoting for more efficient exchange of information when you control both ends of the application. Use Web services for open-protocol-based information exchange when you are just a client or a server with the other end belonging to someone else.

  • What security measures exist for .NET Remoting in System.Runtime.Remoting?

None. Security should be taken care of at the application level. Cryptography and other security techniques can be applied at application or server level.

  • What’s a Windows process?

It’s an application that’s running and had been allocated memory.

  • What distributed process frameworks outside .NET do you know?

Distributed Computing Environment/Remote Procedure Calls (DEC/RPC), Microsoft Distributed Component Object Model (DCOM), Common Object Request Broker Architecture (CORBA), and Java Remote Method Invocation (RMI).

  • What’s a proxy of the server object in .NET Remoting?

It’s a fake copy of the server object that resides on the client side and behaves as if it was the server. It handles the communication between real server object and the client object. This process is also known as marshaling.

  • What’s typical about a Windows process in regards to memory allocation?

Each process is allocated its own block of available RAM space, no process can access another process’ code or data. If the process crashes, it dies alone without taking the entire OS or a bunch of other applications down.

  • Can you configure a .NET Remoting object via XML file?

Yes, via machine.config and application level .config file (or web.config in ASP.NET). Application-level XML settings take precedence over machine.config.

  • What are remotable objects in .NET Remoting?

Remotable objects are the objects that can be marshaled across the application domains. You can marshal by value, where a deep copy of the object is created and then passed to the receiver. You can also marshal by reference, where just a reference to an existing object is passed.

  • Advantage over Web Services?
  1. It works using purely Commmon Type System.
  2. It supports high speed binary over tcp/ip communication.
  • Advantage over COM/DCOM?
  1. It does not have extra interface language (IDL)
  2. It Works using purely managed code
  3. It's using Common Type System.. No Safearrays etc
  • Disadvantages
  1. It is not an open standard like web services.
  2. It is not as widespread and established ad DCOM.
  3. Less support for transactions,load balancing compared with DCOM.
  • Choosing between HTTP and TCP for protocols and Binary and SOAP for formatters, what are the trade-offs?

Binary over TCP is the most effiecient, SOAP over HTTP is the most interoperable.

  • Why do you call it a process?What’s different between process and application in .NET, not common computer usage, terminology?

A process is an instance of a running application. An application is an executable on the hard drive or network. There can be numerous processes launched of the same application (5 copies of Word running), but 1 process can run just 1 application.

  • How many processes can listen on a single TCP/IP port?

One.

Happy Programming!!!