Static Constructor

  • A static constructor is used to initialize the static data once or performed an action to once only.
  • A static constructor does not take access modifiers or have parameters.
  • A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
  • User has no control when static constructor executed. In real life scenario static constructor use when class write the log file.

Is MVC Design Pattern or Architectural Pattern?
MVC is an architectural pattern. ASP.NET MVC is a part of ASP.NET Web application framework.

Caching
Caching is a use to improve performance of website by storing frequently access data and reusing that data.
Advantages: Reduce hosting server round trip. Reduce database server round trips. Reduce network traffic.
Disadvantages: Avoid caching if data unique per user. Avoid caching if database server has not enough RAM. For caching of dynamic contents that change frequently, define a short cache–expiration time rather than disabling caching.

Delegates
A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class.

Difference between Web Services, WCF and Web API
Web Services

  • It supports only http protocol.
  • It is based on SOAN and return data in XML format only
  • It can be host only on IIS

WCF

  • It supports http, https, tcp, MSMQ protocol.
  • It is based on SOAP and return data in XML format only
  • It can be hosted with in the applicaion or on IIS or using window service
  • WCF Rest support XML, JSON and ATOM data format.

Web API

  • It supports http protocol.
  • It is supports MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.
  • It can be hosted with in the application or on IIS.
  • WCF Rest support XML, JSON data format.

Components of WCF
There are three main components in WCF.

  • Service Class
  • Hosting Environment
  • End Point

Service Class
Service Contract attribute define saying which application interface will be exposed as a service.

[ServiceContract()]
public interface IServiceGetResult
{
}

Operation Contract
Operation Contract dictates which methods should be exposed to the external client using this service.

[ServiceContract()]
public interface IServiceGetResult
{
[OperationContract()]
decimal GetPercentage(Student model);
}

Data Contract
Data Contract attributes defines which type of complex data will be exchanged between the client and the service. They determine which parameters to be serialized. When you are using simple data types like int, it is not necessary that you need to mark the data contract attribute. Because you will always find matching types on the client. However, complex structure like one shown in the below code snippet you will need to define a data contract. Remember data contract define how this data will be passed during transmission. In short data contract attribute define how data will be serialized will transmission.

As data contract are all about serialization you need to import System.Runtime.Serialization name space.
[DataContract]
public class Student
{
int StudentId {get;set;}
string GrNo {get;set;}
string Name {get;set;}
}
public class serviceGetResult: IServiceGetResult
{
public decimal GetPercentage(Student model)
{
decimal percentage=100;
//get percentage stored procedure call or calculation here.
return percentage;
}
}

Hosting Environment
Self-hosting the service in his own application domain. The service comes in to existence when you create the object of Service Host class and the service closes when you call the Close of the Service Host class.

Host in application domain or process provided by IIS Server.

Host in Application domain and process provided by WAS (Windows Activation Service) Server.

End Points
WCF offers its services to its client using an endpoint. An endpoint comprises of three key elements, the address, binding and contract.

WCF endpoints provide the necessary resources and directions, which help clients to communicate with the various services WCF offers.

We commonly refer the three elements (attributes) as ABC.

01) A stands for Address
02) B stands for Binding
03) C stands for Contract

Advertisements