Advanced .NET Framework Concepts-Interview Questions

No.of Views694
Bookmarked0
By Pankaj Kumar Gupta  On 10 Mar 2011
emailbookmarkadd commentsprint
 

1. What is .NET Remoting?

One Process can have multiple application domains and to invoke a method in an object running in different application domain .NET remoting is used. .NET remoting enables you to build widely distributed applications easily, whether application components are all on one computer or spread out across the entire world. You can build client applications that use objects in other processes on the same computer or on any other computer that is reachable over its network. You can also use .NET remoting to communicate with other application domains in the same process. (For details about programming application domains, see Programming with Application domains.)

.NET remoting provides an abstract approach to inter-process communication that separates the remotable object from a specific client or server application domain and from a specific mechanism of communication. As a result, it is flexible and easily customizable.

We can replace one communication protocol with another or one serialization format with another without recompiling the client or the server. In addition, the remoting system assumes no particular application model. You can communicate from a Web application, a console application, a Windows Service – from almost anything you want to use. Remoting servers can also be any type of application domain. Any application can host remoting objects and provide its services to any client on its computer or network. To use .NET remoting to build an application in which two components communicate directly across an application domain boundary, you need to build only the following:

  • A Remotable Object.
  • A Host Application Domain to listen for requests for that Object.
  • A Client Application Domain that makes requests for that Object.

 

2. What are the types of remote object creation modes in .NET?

There are two different ways in which object can be created using Remoting:-

1). SAO (Server Activated Objects) also called as Well-Known Call Mode.
2). CAO (Client Activated Objects) SAO has two modes “Single Call” and “Singleton”.

With Single Call object the object is created with every method call thus making the object stateless. With Singleton the object is created only once and the object is shared with all clients.
CAO are stateful as compared to SAO. In CAO the creation request is sent from client side. Client holds a proxy to the server object created on server.

3. What is the difference between Well-Known and Client-Activated Server Objects?

There is no permanent or constant connection maintained with Well-Known objects.  In much the same way a browser is disconnected from the web server, well-known objects are connected to, worked with, and then disconnected.  Client-Activated objects maintain a connection until their task is complete.  Similar in concept to a TCP/IP socket connection application works (some TCP/IP apps choose to work in a disconnected environment). 
Well-Known objects come in two different types: Singleton and Single-Call. Your production application may end up using both depending on your requirements.

4. What is the difference between Singleton and Single-Call well-known objects?

A well-known singleton object is created by the first user to access it and is used, shared, and maintained in memory until the server service/application shuts down.  So, if you use properties in your class, their values will be shared across all client connections that access them. Similar in nature to a public static variable. In the code sample below, you have the option to watch the process in use with a singleton object .vs a single-call object.  Notice that when you launch multiple instances of the client application, the server class constructor only fires once.  Well-known single-call objects are quite different.  Every client access triggers the server class constructor.  Thus, making properties obsolete because the object is not held in memory server side in between references from the same client.  Single-call objects are ideal for classes that hold methods across a server farm.

5. Which class does the remote object has to inherit?

All remote objects should inherit from System.MarshalbyRefObject.

6.What are the ways clients can create object on server in CAO Model?

There are two ways by which you can create Client Objects on Remoting Server:-

1)    By Using: Activator.CreateInstance().
2)    By Using Keyword “New”.

6. How can we call methods in remoting asynchronously?

In synchronous method calls client has to wait until the method completes the process. By using Delegates we can make Asynchronous method calls.

7. What is Extensible Markup Language (XML)?

XML is a markup language for documents containing structured information.

Uses of XML

  • You can define your own elements and thereby support a much wider variety of information display. XML may be used to describe chemical structures, or other scientific or artistic data that cannot be readily displayed using HTML.
  • Documents may be better organized into structures to allow for easier reference using and generating items like a table of contents.
  • XML allows elements to be used to sort through database information readily.

Features of XML

  • Properly nested
  • Case sensitive
  • Text based
  • Compatible with the existing standards like Html,...

8. What is XSL?

Extensible Style-Sheet Language (XSL) allows you to format and reorganize existing XML documents into another format (for example, XML or HTML)

Uses of XSL

  • XSL can be used for many XML transformation and reformatting tasks.
  • The transformation and reformatting tasks that you can do with XSL include the following:
  • XML to HTML rendering
  • XML vocabulary conversion
  • XML to plain text conversion
  • Simple XML queries

9. Why is XML such an important development?

It removes two constraints which were holding back Web developments:

  • Dependence on a single, inflexible document type (HTML);
  • The complexity of full SGML, whose syntax allows many powerful but hard-to-program options.

XML simplifies the levels of optionally in SGML, and allows the development of user-defined document types on the Web.

10. How do I execute or run an XML file?

You can't and you don't. XML is not a programming language, so XML files don't `run' or `execute’. XML is a markup specification language and XML files are data: they just sit there until you run a program which displays them (like a browser) or does some work with them (like a converter which writes the data in another format, or a database which reads the data), or modifies them (like an editor).

11. How XML is supported in ADO.NET?

The dataset is represented in the memory as an XML document. You can fill the dataset by XML and can also get the result in the form of XML. Since XML is an international and widely accepted standard, you can read the data using the ADO.Net in the XML form and pass it to other applications using Web Service. These data consuming application need not be the essentially Dot Net based. They may be written with Java, C++ or any other programming language and running on any platform.

12. What are Web Services?

Web Services are business logic components which provide functionality via the Internet using standard protocols such as HTTP. Web Services uses Simple Object Access Protocol (SOAP) in order to expose the business functionality. SOAP defines a standardized format in XML which can be exchanged between two entities over standard protocols such as HTTP.SOAP is platform independent so the consumer of a Web Service is therefore completely shielded from any implementation details about the platform exposing the Web Service. For the consumer it is simply a black box of send and receives XML over HTTP. So any web service hosted on windows can also be consumed by UNIX and LINUX platform.

13. What is UDDI?

Full form of UDDI is Universal Description Discovery and Integration. It is a directory that can be used to publish and discover public Web Services. If you want to see more details you can visit the http://www.UDDI.org.

14. What is DISCO?

Abbreviation of DISCO is Discovery. It is basically used to club or group common services together on a server and provides links to the schema documents of the services it describes may require.

15. What is WSDL?

Web Service Description Language (WSDL)is a W3C specification which defines XML grammar for describing Web Services.XML grammar describes details such as:-

  1. Where we can find the Web Service (its URI)
  2. What methods and properties that service supports
  3. Data type support.
  4. Supported protocols in short it’s a bible of what the web service can do. Clients can consume this WSDL and build proxy objects that clients use to communicate with the Web Services. Full WSDL specification is available at http://www.w3.org/TR/wsdl.

16. What the different phases/steps for acquiring a proxy object in Web Service?

The following are the different steps needed to get a proxy object of a web service at the client side:-

  • Client communicates to UDI node for Web Service either through browser or UDDI's public web service.
  • UDII responds with a list of web service.
  • Every service listed by web service has a URI pointing to DISCO or WSDL document.
  • After parsing the DISCO document, we follow the URI for the WSDL document related to the web service which we need.
  • Client then parses the WSDL document and builds a proxy object which can communicate with Web Service.

17. Which attribute is used in order that the method can be used as Web Service?

WebMethod attribute has to be specified in order that the method and property can be treated as Web Service.

18. What are differences between Web Services and Remoting?

  •  Remoting supports the Binary & XML data to transfer across the Network. Web Services is only supports the XML Data.
  •  Web Services is use the Standard Protocol to communicate between the client and the server. But remoting use the channels.
  •  Web Services can call from HTTP POST/HTTP GET or SOAP protocols.
  • These are general & always open protocol for any network. (SOAP you need to Configure to open the protocol to access the current user, Otherwise it give the 401. Access Denied Error)
  •  The Web Services converts the object into XML format. So it can be readable by any Language/Platform. But remoting is only for Managed Code - CLR to CLR. The Web Services can used in WAN/LAN.Remoting - HTTP Channel supports WAN.
  •  You can send any object-not only file across the network. But it should be Serilizable.
  • The XMLSerilizer doesn’t support some Objects, Like IDictonary. ICollection etc. So you can't able to send these Objects with Web Services but the .NET Remoting Supports all the Objects if you choose the Binary Formatter as Communication). For example, you can pass the DataSet object in WEB Services but the DataRow is not supported by Web Services.
  •  Web Services supports the Web-Reference. I.e. you need not to create WSDL on your machine. If you add the Web-Reference it automatically convert the XML data in to the .NET Classes.

19. What are Delegates?

A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value, as in this example:

public delegate int PerformCalculation(int x, int y); 

Any method that matches the delegate's signature, which consists of the return type and parameters, can be assigned to the delegate.

Delegates have the following properties:-

  • Delegates are similar to C++ function pointers, but are type safe.
  • Delegates allow methods to be passed as parameters.
  • Delegates can be used to define callback methods.
  • Delegates can be chained together; for example, multiple methods can be called on a single event.
  • Methods don't need to match the delegate signature exactly
  • Delegates are type-safe functions pointers or callbacks.

20. What is Event?

An event is just a formalized software pattern in which a notification source makes callbacks to one or more handler methods. Events are therefore similar to interfaces and delegates because they provide a means to design applications that use callback methods. However, events add a valuable degree of productivity because they are easier to use than interfaces or delegates. Events allow the compiler and the Visual Studio® .NET IDE to do much of the work for you behind the scenes. A design that involves events is based on an event source and one or more event handlers. An event source can be either a class or an object.

21. What is an event handler?

An event handler is a delegate object that's bound to a handler method.

22. What’s difference between delegate and events?

Actually events use delegates in bottom. But they add an extra layer on the delegates, thus forming the publisher and subscriber model.

As delegates are function to pointers they can move across any clients. So any of the clients can add or remove events, which can be pretty confusing. But events give the extra protection by adding the layer and making it a publisher and subscriber model. Just imagine one of your clients doing this: c.XyzCallback = null this will reset all your delegates to nothing and you have to keep figuring where the error is.

23. What is a thread?

Multitasking is a feature of modern operating systems with which we can run multiple programs at same time example Word, Excel etc. Multi-threading forms subset of Multi-tasking instead of having to switch between programs this feature switches between different parts of the same program. Example you are writing in word and at the same time word is doing a spell check in background.

A thread is the basic unit to which the operating system allocates processor time.

24. Can we have multiple threads in one App Domain?

One or more threads run in an AppDomain. An AppDomain is a runtime representation of a logical process within a physical process. Each AppDomain is started with a single thread, but can create additional threads from any of its threads. Note:- All threading classes are defined in System.Threading namespace.

25. How can we change priority and what the levels of priority are provided by .NET?

Thread Priority can be changed by using Threadname.Priority = ThreadPriority.Highest. In the sample provided look out for code where the second thread is ran with a high priority. Following are different levels of Priority provided by .NET:-

1)    ThreadPriority.Highest
2)    ThreadPriority.AboveNormal
3)    ThreadPriority.Normal
4)    ThreadPriority.BelowNormal
5)    ThreadPriority.Lowest

26. How can you reference current thread of the method?

"Thread.CurrentThread" refers to the current thread running in the method."CurrentThread" is a public static property.

27. What is Thread.Sleep() in threading?

Thread's execution can be paused by calling the Thread.Sleep() method. This method takes an integer value that determines how long the thread should sleep. Example Thread.CurrentThread.Sleep(2000).

28. What do you mean by Serialization and Deserialization?

Serialization is the process of converting the state of an object into a form that can be persisted or transported. The complement of serialization is deserialization, which converts a stream into an object. Together, these processes allow data to be easily stored and transferred. 

Image Loading

29. What are the uses of Serialization?

Serialization is used in many scenarios, but the main purpose is to save the state of an object in order to have the ability to recreate the same object when required. It is an important to let the user save work and then be able to continue from that point at a later time. This is a common need in various tools and applications. Serialization is also used in creating a clone of an object.

Another important need for serialization arises when the object is required to travel electronically over wire. In such cases the objects are serialized and deserialized. In fact, serialization is one of the fundamental requirements for techniques such as .NET Remoting.

Even the hibernation mode in the Windows Operating system can be considered a form of serialization.

30. What are the types of Serialization?

The .NET Framework provides certain built-in mechanisms which can be used to serialize and deserialize objects. This functionality can be found in the System.Runtime.Serialization and the System.Xml.Serialization namespaces of the .NET Framework. Serialization in .NET can be classified into four types as shown below: 

Image Loading

This classification arises from the format in which the data in the object is persisted. Each of the serialization techniques mentioned have different capabilities and each excel in specific scenarios. The XML serialization technique can convert only the public properties and fields of an object into an XML format. The XML serialization is also known as shallow serialization.

This inability of the XMLSerializer to serialize the private fields of an object is overcome by the SOAP and binary serialization techniques. In the binary and SOAP serialization techniques, the state of the entire object is serialized into a stream of bytes. In cases where the object contains a reference to other objects, even those are serialized. This type of serialization is known as deep serialization.

In addition to these techniques, the .NET Framework also provides the developer control over the serialization process. This can be achieved by implementing the ISerializable interface

 
 
About Author
 
Pankaj Kumar Gupta
Occupation-Software Engineer
Company-Miri Infotech (P) Ltd, India
Member Type-Junior
Location-India
Joined date-27 Oct 2010
Home Page-www.codegain.com
Blog Page-codegain.com
- I am working with Miri Infotech (P) Ltd, India as Senior Software Engineer. - Having 5+ years experience in .NET Technologies (ASP.NET, C#.net, VB.net, SQL Server, XML, Web Services, MS Dynamics CRM, SharePoint). - I have masters M.Sc-Computer Science, M.Tech-Information Technology with Honours. - I have completed MCP, MCSD.NET, MCAD, MCDBA SQL Server, MCTS, MCPD-EAD - Microsoft Certified Professional & Technology Specialist - Obsessed in OOP, MVC, MVP style design and programming. - Designing and developing the client/server applications for a number of doimains. - Designing and implementing Business Planning Tools & Applications. - Good understanding of formal software engineering tools & technologies.
 
 
Other popular Interview Questions On .NET Frameworks
^ Scroll to Top