ASP.NET Exclusive Interview Questions and Answers (348) - Page 3

  • A joint initiative from DotNetFunda.Com and Questpond.
  • A one stop place on the internet to get trusted and proven Interview Questions (based on more than a decade of experience in this field) to ensure the success of the candidates.
  • You will find almost all Interview questions from Questpond here and this list is growing day by day with all latest and updated interview questions.

348 records found.

Get 650+ Questpond's Interview videos on discount

Which namespace is needed to implement debug and trace?

Answer: -
Debug and trace class belongs to ‘System.Diagnostic’ namespace.


Can you explain the concept of trace listener?

Answer: -
‘Tracelistener’ are objects that get tracing information from the trace class and they output the data to some medium. For instance you can see from the figure ‘TraceListener’ how it listens to the trace object and outputs the same to UI, File or a windows event log. There are three different types of ‘tracelistener’ first is the ‘defaulttracelistener’ (this outputs the data to UI), second is ‘textwritertracelistener’ (this outputs to a file) and the final one is ‘Eventlogtracelistener’ which outputs the same to a windows event log.




Below is a code snippet for ‘textwritertracelistener’ and ‘eventlogtracelistener’. Using ‘textwritertracelistener’ we have forwarded the trace’s to ‘ErrorLog.txt’ file and in the second snippet we have used the ‘Eventlogtracelistener’ to forward the trace’s to windows event log.



 


What are trace switches?

Answer: -
Trace switches helps us to control and govern the tracing behavior of a project. There are two types of trace switches ‘BooleanSwitch’ and ‘TraceSwitch’. BooleanSwitch, as the name says, is a kind of on/off switch which can be either enabled (true) or disabled (false).




‘TraceSwitch’ on the other hand offers more options rather than simple true/false like ‘BooleanSwitch’. Tracing is enabled for a TraceSwitch object using the Level property. When we set the Level property of a switch to a particular level, it includes all levels from the indicated level down. For example, if you set a TraceSwitch's Level property to TraceLevel.Info, then all the lower levels, from TraceLevel.Error to TraceLevel.Warning, will be taken in to account. Below are the various levels in ‘TraceSwitch’ object.
Off a Outputs no messages to Trace Listeners
Error a Outputs only error messages to Trace Listeners
Warning a Outputs error and warning messages to Trace Listeners
Info a Outputs informational, warning and error messages to Trace Listeners
Verbose a Outputs all messages to Trace Listeners

TraceSwitch objSwitch = new TraceSwitch("TraceWarningandError", "Error in trace") ;
objSwitch.Level = TraceLevel.Warning ;


What is SOA?

SOA stands for service oriented architecture. Before we define SOA lets first define a service. In real world service is what we pay for and we get the intended service. For instance you go to a hotel and order food. Your order first goes to the counter and then it goes to the kitchen where the food is prepared and finally the waiter serves the food.




Figure: - Hotel and services



So in order to order a item from a hotel you need the three logical departments / services to work together (counter, kitchen and waiter).

In the same manner in software world these services are termed as business services. They are self contained and logical. So let’s first define a business service, SOA definition will be just an extension of the same.

Definition of business service: - It’s a logical encapsulation of self contained business functionality.
For instance figure ‘order system’ shows a simple ordering system which is achieved by different services like payment gateway, stock system and delivery system coming together. All the services are self contained and logical. They are like black boxes. In short we do not need to understand the internal details of how the business service works. For the external world it’s just a black box which takes messages and serves accordingly. For instance the ‘payment gateway’ business service takes message ‘check credit’ and gives out output does the customer have credit or not. For the ‘order system’ business service ‘payment gateway’ service is a black box.



Figure: - Order system



Now let’s revise some bullet points of SOA before we arrive to a definition of SOA.

SOA components are loosely coupled. When we say loosely coupled means every service is self contained and exist in alone logically. For instance we take the ‘payment gateway’ service and attach it to a different system.
SOA services are black boxes. In SOA services hide there inner complexities. They only interact using messages and send services depending on those messages. By visualizing services as black boxes services become more loosely coupled.
SOA service should be self defined: - SOA services should be able to define themselves.
SOA Services are maintained in a listing: - SOA services are maintained in a central repository. Applications can search the services in the central repository and use them accordingly.
SOA components can be orchestrated and linked to achieve a particular functionality. SOA services can be used/orchestrated in a plug and play manner. For instance figure ‘Orchestration’ shows two services ‘Security service’ and ‘Order processing service’. You can achieve two types of orchestrations from it one you can check the user first and then process order or vice-versa. Yes you guessed right using SOA we can manage work flow between services in a loosely coupled fashion.



Figure: - Orchestration


So let us define SOA.

SOA is a architecture for building business applications using loosely coupled services which act like black boxes and can be orchestrated to achieve a specific functionality by linking together.


In SOA do we need to build systems from scratch?

No. If you need to integrate or make an existing system as a business service, you just need to create loosely coupled wrappers which will wrap your custom systems and expose the systems functionality in generic fashion to the external world.


Can you explain business layers and plumbing layers in SOA?

In SOA we can divide any architecture in two layers. The first which has direct relevance to business as it carries out business functions. The second layer is a technical layer which talks about managing computer resources like database, web server etc. This division is needed to identify a service. Consider the figure ‘Simple order system’. It has various components which interact with each other to complete the order system functionality.


Figure: - Simple order System


The simple order system can be divided in to two layers (see figure ‘business and plumbing layer’ one which is business related and second which is more technical related. You can see the plumbing layer consisting of data access layer , AJAX , yes more of technical stuff.



Figure: - Business layer and plumbing layer


What’s the difference between services and components?

Services are logical grouping of components to achieve business functionality. Components are implementation approaches to make a service. The components can be in JAVA, C#, C++ but the services will be exposed in a general format like Web Services.


Can you describe the complete architecture of SOA?

Figure ‘Architecture of SOA’ shows a complete view of a SOA. Please note this architecture diagram is not tied up with implementation of Microsoft, IBM etc. It’s a general architecture. Any vendor who implements SOA needs to fulfill the below SOA components. How they do it is completely their own technological implementation.



Figure: - Architecture of SOA



The main goal of SOA is to connect disparate systems. In order that these disparate system work they should messages to each other. ESB (Enterprise service bus) acts like a reliable post office which guarantees delivery of messages between systems in a loosely coupled manner. ESB is a special layer which delivers messages between applications. In the figure we have shown a huge plump pipe. It’s not hardware or some wire etc. It’s a group of components/software which helps you to send and receive messages between the disparate applications. Do not try to code your own ESB, you can think of buying one from Microsoft, IBM, Oracle, progress etc.

SOA registry is like a reference database of services. It describes what each services do, where are they located and how can they communicate. It’s a central reference of meta-data for services.

SOA workflow allows us to define work flow using the services in SOA registry. We will read more about BPM in the further questions.

Service broker reads the work flow and takes services from the SOA registry and ties them together. Service brokers are normally middleware like EAI (Enterprise application Integration) products. You can get a list of decent EAI from Sun, Microsoft, and IBM etc.

Process manager is nothing but the collection of SOA registry, SOA workflow and service broker.

SOA supervisor is traffic cop ensuring that services do not have issues. It deals mainly with performance issues of the system so that appropriate service levels are met. If any of the services have performance problems it sends messages to the proper infrastructure to fix the issue.

Note: - The above explanation is of general architecture for SOA. Any vendor (Microsoft, IBM, SUN etc) who gives solution for SOA should have the above components in some or other manner. As this is a Software architecture book, we will not be covering specific vendor implementation. We would advise the reader to map the same to their vendor products for better understanding.


What are ends, contract, address, and bindings?

These three terminologies on which SOA service stands. Every service must expose one or more ends by which the service can be available to the client. End consists of three important things where, what and how:-

Contract (What)
Contract is an agreement between two or more parties. It defines the protocol how client should communicate with your service. Technically, it describes parameters and return values for a method.

Address (Where)
An Address indicates where we can find this service. Address is a URL, which points to the location of the service.

Binding (How)
Bindings determine how this end can be accessed. It determines how communications is done. For instance, you expose your service, which can be accessed using SOAP over HTTP or BINARY over TCP. So for each of these communications medium two bindings will be created.

Below figure, show the three main components of end. You can see the stock ticker is the service class, which has an end hosted on www.soa.com with HTTP and TCP binding support and using Stock Ticker interface type.



Figure: - Endpoint Architecture



Note: - You can also remember the end point by ABC where A stands for Address, B for bindings and C for Contract.


Are web-services SOA?

SOA is a thinking, it’s an architectural concept and web service is one of the technical approach to complete it. Web services are the preferred standards to achieve SOA.

• In SOA we need the services to be loosely coupled. A web service communicates using SOAP protocol which is XML based which is very loosely coupled. It answers the what part of the service.

• SOA services should be able to describe themselves. WSDL describes how we can access the service.

• SOA services are located in a directory. UDDI describes where we can get the web service. This nothing but implementation of SOA registry.


What is an application object?

Application object can be used in situation where we want data to be shared across users globally.


What is the difference between Cache object and application object?

The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.


How can get access to cache object?


The Cache object is defined in the ‘System.Web.Caching’ namespace. You can get a reference to the Cache object by using the Cache property of the Http Context class in the ‘System.Web’ namespace or by using the Cache property of the Page object.


What are dependencies in cache and types of dependencies?

When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of dependencies. Example if the cache object is dependent on file and when the file data changes you want the cache object to be update.

Following are the supported dependency:-

• File dependency: - Allows you to invalidate a specific cache item when a disk based file or files change.

• Time-based expiration: - Allows you to invalidate a specific cache item depending on predefined time.

• Key dependency:- Allows you to invalidate a specific cache item depending when another cached item changes.


Can you show a simple code showing file dependency in cache?

Partial Class Default_aspx

Public Sub display Announcement()
Dim announcement As String


If Cache(“announcement”) Is Nothing Then
Dim file As New _
System.IO.StreamReader _
(Server.MapPath(“announcement.txt”))
announcement = file.ReadToEnd
file. Close()
Dim depends As New _
System.Web.Caching.CacheDependency _
(Server.MapPath(“announcement.txt”))
Cache.Insert(“announcement”, announcement, depends)
End If
Response.Write(CType(Cache(“announcement”), String))
End Sub

Private Sub Page_Init(ByVal sender As Object, By Val e As System.EventArgs) Handles Me. nit
display Announcement()
End Sub
End Class

Note: - Above source code can be obtained from CD in “CacheSample” folder.”Announcement.txt” is in the same folder which you can play around to see the results.


Above given method display Announcement() displays banner text from Announcement.txt file which is lying in application path of the web directory. Above method, first checks whether the Cache object is nothing, if the cache object is nothing then it moves further to load the cache data from the file. Whenever the file data changes the cache object is removed and set to nothing.


What is Cache Callback in Cache?


Cache object is dependent on its dependencies example file based, time based etc...Cache items remove the object when cache dependencies change.ASP.NET provides capability to execute a callback method when that item is removed from cache.


What is scavenging?

When server running your ASP. NET application runs low on memory resources, items are removed from cache depending on cache item priority. Cache item priority is set when you add item to cache. By setting the cache item priority controls, the items scavenging are removed according to priority.


What are different types of caching using cache object of ASP.NET?

You can use two types of output caching to cache information that is to be transmitted to and displayed in a Web browser: -

• Page Output Caching
Page output caching adds the response of page to cache object. Later when page is requested page is displayed from cache rather than creating the page object and displaying it. Page output caching is good if the site is fairly static.

• Page Fragment Caching
If parts of the page are changing, you can wrap the static sections as user controls and cache the user controls using page fragment caching.


How can you cache different version of same page using ASP. NET cache object?

Output cache functionality is achieved by using “OutputCache” attribute on ASP. NET page header. Below is the syntax


<%@ Output Cache Duration="20" Location="Server" Vary By Param="state" Vary By Custom="minor version" Vary By Header="Accept-Language"%>


• Vary By Param: - Caches different version depending on input parameters send through HTTP POST/GET.
• Vary By Header: - Caches different version depending on the contents of the page header.
• Vary By Custom: -Lets you customize the way the cache handles page variations by declaring the attribute and overriding the Get Vary By Custom String handler.
• Vary By Control: -Caches different versions of a user control based on the value of properties of ASP objects in the control.


More ASP.NET Interview Questions & Answers here

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Exclusive Interview Questions and Answers Categories