Wednesday 10 September 2014

asp.net Questions and Answers


What is difference between HTTP Handler and HTTP Module.

Here are the difference between HTTP Handlers and HTTP Modules.
Http Handlers:
Http handlers are component developed by asp.net developers to work as end point to asp.net pipeline. It has to implement System.Web.IHttpHandler interface and this will act as target for asp.net requests. Handlers can be act as ISAPI dlls the only difference between ISAPI dlls and HTTP Handlers are Handlers can be called directly URL as compare to ISAPI Dlls.
Http Modules:
Http modules are objects which also participate in the asp.net request pipeline but it does job after and before HTTP Handlers complete its work. For example it will associate a session and cache with asp.net request. It implements System.Web.IHttpModule interface.
HTTP Handler implement following Methods and Properties
  1. Process Request: This method is called when processing asp.net requests. Here you can perform all the things related to processing request.
  2. IsReusable: This property is to determine whether same instance of HTTP Handler can be used to fulfill another request of same type.
Http Module implements following Methods and Properties.
  1. InIt: This method is used for implementing events of HTTP Modules in HTTPApplication object.
  2. Dispose: This method is used perform cleanup before Garbage Collector destroy everything.
An Http Module can Support following events exposed to HTTPApplication Object.
  1. AcquireRequestState: This event is raised when asp.net request is ready to acquire the session state in http module.
  2. AuthenticateRequest: This event is raised when asp.net runtime ready to authenticate user.
  3. AuthorizeRequest: This event is raised when asp.net request try to authorize resources with current user identity.
  4. BeginRequest: This event is raised when HTTP Modules receive new request.
  5. EndRequest: This event is raised before sending response to client.
  6. Disposed: This event is raised when http modules completes processing of request
  7. Error: This event is raised when any error occurs during processing of request.
  8. PreRequestHandlerExecute: This event is raised just before ASP.NET begins executing a handler for the HTTP request. After this event, ASP.NET will forward the request to the appropriate HTTP handler.
  9. PostRequestHandlerExecute: This event is raised when when HTTP Handler will finish the execution of current request.
  10. PreSendRequestContent: This event is raised just before ASP.NET sends the response contents to the client. This event allows us to change the contents before it gets delivered to the client. We can use this event to add the contents, which are common in all pages, to the page output. For example, a common menu, header or footer.
  11. PreSendRequestHeaders: This event is raised before asp.net Just send response header to client browser.
  12. ReleaseRequestState: This event is raised when asp.net runtime finishes handling of all the request.
  13. ResolveRequestCache: This event is raised to determine whether the request can be fulfilled by returning the contents from the Output Cache.
  14. UpdateRequestCache: This event is raised when ASP.NET has completed processing the current HTTP request and the output contents are ready to be added to the Output Cache.
WHat is Rest API?
Difference between API and Rest API.

C# - Types of Polymorphism in C#.Net with Example | Basic Polymorphism in C#.NET

difference between compile time and  Run-time Polymorpism?


Polymorphism
Polymorphism means many forms (ability to take more than one form). In Polymorphism poly means “multiple” and morph means “forms” so polymorphism means many forms.
In polymorphism we will declare methods with same name and different parameters in same class or methods with same name and same parameters in different classes. Polymorphism has ability to provide different implementation of methods that are implemented with same name.
In Polymorphism we have 2 different types those are
        -   Compile Time Polymorphism (Called as Early Binding or Overloading or static binding)
        -   Run Time Polymorphism (Called as Late Binding or Overriding or dynamic binding)
Compile Time Polymorphism
Compile time polymorphism means we will declare methods with same name but different signatures because of this we will perform different tasks with same method name. This compile time polymorphism also called as early binding or method overloading.
Method Overloading or compile time polymorphism means same method names with different signatures (different parameters)
Example
public class Class1
{
public void NumbersAdd(int a, int b)
{
Console.WriteLine(a + b);
}
public void NumbersAdd(int a, int b, int c)
{
Console.WriteLine(a + b + c);
}
}
In above class we have two methods with same name but having different input parameters this is called method overloading or compile time polymorphism or early binding. 

Run Time Polymorphism

Run time polymorphism also called as late binding or method overriding or dynamic polymorphism. Run time polymorphism or method overriding means same method names with same signatures.
In this run time polymorphism or method overriding we can override a method in base class by creating similar function in derived class this can be achieved by using inheritance principle and using “virtual & override” keywords.
In base class if we declare methods with virtual keyword then only we can override those methods in derived class using override keyword
Example
//Base Class
public class Bclass
{
public virtual void Sample1()
{
Console.WriteLine("Base Class");
}
}
// Derived Class
public class DClass : Bclass
{
public override void Sample1()
{
Console.WriteLine("Derived Class");
}
}
// Using base and derived class
class Program
{
static void Main(string[] args)
{
// calling the overriden method
DClass objDc = new DClass();
objDc.Sample1();
// calling the base class method
Bclass objBc = new DClass();
objBc.Sample1();
}
}
If we run above code we will get output like as shown below
Output

----------------------------------
Derived Class
Derived Class


What is immutable?
string in C# is immutable(read-only) 


Once you have assigned it, you can't change the original string value. If you try to alter it in some way, perhaps by appending another string it creates a new string. This can be very inefficient if done a lot but there is a StringBuilder class that will overcome that.


Difference between string and stringBuilder?

stringBuilder has methods to let you Append, Replace, Insert, and Remove characters from a StringBuilder String. You can also directly access and manipulate the chars in the object by indexing. 

 StringBuilder SB = "HEllo World";
 SB[1]='e'; // Changes it to Hello World

 

 





Why String is a reference type while Integer is a Value type?


An integer has fixed memory set at 4 bytes.  Hence, an integer can be directly stored within fixed memory, or on the stack.
Alternatively, a string does not have a pre-defined memory size, so it requires dynamic memory.  When a string object is created, the actual value is stored within dynamic memory, or on the heap.  To access it, a reference to this memory space is stored in the stack, thus the name "reference type".
Note that when you create an object variable, a value-type variable contains the actual value whereas a reference-type variable contains only the reference to the actual location of the object's value.


Difference B/W char and string? 

 

Difference B/w value type and ref type?

value type store on stack and ref type on heap

 what is endpoints in WCF?

how many http bindings are there in WCF?

what are contracts?

 

there are different type of parameters option in a function like value type,reference type , param type ,out type .Explain them with difference?

 

difference b/w abstract class and interface?

Can we creat object of interface ? and if yes how?

 

what are generics?

 

Covariance and Contravariance in Generics

 http://www.codeproject.com/Articles/72467/C-Covariance-And-Contravariance-In-Generics


What is WCF ?

  • Stands for Windows Communication Foundation.
  • Its code name is “Indigo”.
  • It is a framework for building, configuring and deploying interoperable distributed services.
  • It enables you to write more secure flexible services without any code change (using configuration).
  • It also provide built-in support for logging. You can enable/disable logging using configuration.
WCF = Web Service + Remoting + MSMQ + COM+
or
WCF = ASMX + .Net Remoting + WSE + Messaging + Enterprise Services

What are the transport schemes supported by WCF ? Give example of address for each scheme.

Following are the transport schemes supported by WCF:
  • HTTP/HTTPS - http://localhost:8001/MyService
  • TCP - net.tcp://localhost:8002/MyService
  • IPC - net.pipe://localhost/MyPipe
  • Peer network
  • MSMQ - net.msmq://localhost/private/MyQueue
  • Service bus - sb://MyNamespace.servicebus.windows.net/

What is Contract ? What are the types of Contract ?

It is the agreement between client and service which specifies:
  • [ServiceContract] - which services are exposed to the client.
  • [OperationContract] - which operations the client can perform on the service.
  • [DataContract] – which data types are passed to and from the service.
  • [MessageContract] - allow the service to interact directly with messages. Message contracts can be typed or untyped and are useful in interoperability cases when another party has already dictated some explicit (typically proprietary) message format.
  • [FaultContract] -which errors are raised by the service and how the service handles andpropagates errors to its clients.

What is the difference between Web Service and WCF Service ?

Features Web Service WCF
Hosting It can be hosted in IIS. It can be hosted in IIS, WAS (windows activation service), Self-hosting or Windows service
Programming Apply [WebService] attribute to the class to be exposed as a service. Apply [ServiceContract] attribute to the class to be exposed as a service.
Model Apply [WebMethod] attribute to the method exposed to client. Apply [OperationContract] attribute to the method exposed to client.
Supported Operations One-way and Request- Response. One-Way, Request-Response and Duplex.
Logging Needs custom implementation. No custom implementation needed. Can be configured in service config file.
Serialization System.Xml.serialization namespace is used. System.Runtime.Serialization namespace is used.
Supported Encoding XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom. XML 1.0, MTOM, Binary, Custom.
Supported Transports Can be accessed through HTTP, TCP and Custom. Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P(Peer to Peer) and Custom.
Service Types ASMX, .Net Remoting .ASMX, .Net Remoting, WSE(WS* Protocols), MSMQ and Enterprise Services
Supported Protocols Security Security, Reliable messaging, Transactions

How can we host WCF service ?

Every WCF service needs to be hosted in a windows process called the host process. A single host process can host multiple services, and the same service type can be hosted in multiple host processes.

 


What is Endpoint in WCF ?

or

What is ABC in WCF ?

Endpoint = Address (A) + Binding (B) + Contract (C)
Address specifies where the services is hosted.
Binding specifies how to access the hosted service. It specifies the transport, encoding, protocol etc.
Contract specifies what type of data can be sent to or received from the service.
Eg:


 

What is a Delegate?

Delegate is a type which  holds the method(s) reference in an object. It is also referred to as a type safe function pointer.

Advantages

  • Encapsulating the method's call from caller
  • Effective use of delegate improves the performance of application
  • Used to call a method asynchronously

What is Multicast Delegate?

It is a delegate which holds the reference of more than one method.
Multicast delegates must contain only methods that return void, else there is a run-time exception.

Delegate is added using the += operator and removed using the -= operator. 
 for reference

http://www.codeproject.com/Articles/11657/Understanding-Delegates-in-C



Why Delegates?

Delegates are used in the following cases:
  • Delegates can be used to handle(call/invoke) multiple methods on a single event.
  • Delegates can be used to define callback(asynchronous) methods.
  • Delegates can be used for decoupling and implementing generic behaviors.
  • Delegates can be invoked method at runtime.
  • Delegates can be used in LINQ for parsing the ExpressionTree.
  • Delegates can be used in different Design Pattern.

Definition

A delegate(known as function pointer in C/C++) is a references type that invokes single/multiple method(s) through the delegate instance. It holds a reference of the methods. Delegate types are sealed and immutable type.

Types of Delegates

There are three types of delegates that can be used in C#.
  • Single Delegate
  • Multicast Delegate
  • Generic Delegate 
http://www.codeproject.com/Articles/772792/Delegates-and-Types-of-Delegates-in-Csharp

रूस-यूक्रेन संकट लाइव: भारतीयों को 'उपलब्ध किसी भी साधन' के माध्यम से कीव को तत्काल छोड़ने के लिए कहा

  रूस यूक्रेन संकट लाइव: कीव में भारतीय दूतावास ने मंगलवार को जारी एक एडवाइजरी में भारतीयों को  'किसी भी उपलब्ध साधन' के माध्यम से क...