User Not Logged In More Than 15 Days

Sunday 18 May 2014


List of User not logged in more than 15 days Report with HTML Look when send from SQL Server
·         You can create a stored procedure shown below with styling.


·         When you send it through SQL Scheduler ,it will look as below:-

Read more ...

MVC Interview Questions Set 2

Sunday 18 May 2014

1. What is main focus of ASP.NET MVC 4?
Ans. The main focus of ASP.NET MVC 4 is making it easier to develop mobile web applications. Other than mobile web applications it’s focus is also on better HTML5 support and making ASP.NET MVC web application cloud ready. Using new features of ASP.NET MVC 4 you can develop web applications that can work well across different mobile devices and desktop web browsers.

2. What is ASP.NET Web API?
Ans. ASP.NET Web API is a framework for building and consuming HTTP Services. It supports wide range of clients including browsers and mobile devices. It is a great platform for developing RESTful services since it talks HTTP.

3. You can also develop RESTful services using WCF, then why this new framework Web API?
Ans. Yes we can still develop RESTful services with WCF, but there are two things that prompt users to use ASP.NET Web API over WCF for development of RESTful services. First one is ASP.NET Web API is included in ASP.NET MVC which obviously increases TDD approach in the development of RESTful services. Second one is for developing RESTful services in WCF you still needs lot of configurations, URI templates, contracts and endpoints which developing RESTful services using ASP.NET Web API is simple.

4. What are the enhancements done in default project template of ASP.NET MVC 4?
Ans. The enhanced default project template is modern-looking. Along with cosmetic enhancements, it also employs adaptive rendering to look nice in both desktop and mobile browsers without need of any kind of additional customization.

5. Why separate mobile project template while you can render your web application in mobile without additional customization?
Ans. The mobile project template touch-optimized UI using jQuery.Mobile.MVC NuGet Package for smart phones and tablets.

6. What is Display Modes?
Ans. Display Modes is new feature provided in ASP.NET MVC 4. It lets an application select views depending on the browser which is making request. For example, if a desktop browser requests home page of an application it will return Views\Home\Index.cshtml view and if a mobile browser requests home page it will return Views\Home\Index.mobile.cshtml view.

8. What is Bundling and Minification feature provided in ASP.NET MVC 4?
Ans. It reduces number of HTTP requests that a web page needs to make. Bundling and Minification combines individual files into single, bundled file for scripts and CSS and then reduce the overall size by minifying the contents of the bundle.

9. While developing application using ASP.NET MVC 4, I want to provide authentication using popular sites like Facebook or twitter into my web application, is it possible in ASP.NET MVC 4?
Ans. Yes, using DotNetOpenAuth library we can provide authentication using OAuth or OpenID providers. In ASP.NET MVC 4 Internet project template includes this library.

10. What’s the difference between Empty MVC Project template in ASP.NET MVC 3 and ASP.NET MVC 4?
Ans. The ASP.NET MVC 4 Empty project template is really empty. It does not contain any css and js files as compared to previous Empty project template, which contains all these files.

11. What are the main features of ASP.NET MVC used by ASP.NET Web API?
Ans. Routing: ASP.NET Web API uses same convention for configuration mapping that ASP.NET MVC provides. Model Binding and Validation: ASP.NET Web API uses same model binding functionality, but tailored to HTTP specific context related operations only. Filters: The ASP.NET Web API uses lots of filters built-in MVC. Unit Testing: Now it’s based on MVC, truly unit testable.

12. If I want to create resource oriented services that can use full features of HTTP like cache control for browsers, use URI templates to include Task URIs in your responses, versioning and concurrancy using ETags, pass various content types such as images, documents, HTML pages etc. then which is preferred for development of services, WCF or Web API?
Ans. In such scenario Web API would be preferred choice. Using Web APIs we can develop services which utilizes full features of HTTP.

13. Suppose I want to develop services which supports special scenarios like one way messaging, duplex communication, message queues, ete then which is the best way to develop services, WCF or Web API?
Ans. In this scenario WCF suits the requirement. WCF provides all kine of messaging facility.

14. Now, if I want to create services which are exposed over various transport channels like TCP, Named Pipe or even UDP. I also want the support of HTTP transport channel when other transport channels are unavailable then which is the preferred way, WCF or Web API and why?
Ans. For such scenario WCF is preferred way for development of services because WCF support almost all kind of transport mechanism and we need to expose SOAP-based and WebHTTP-based bindings.

15. What is the difference between asynchronous controller implementation between ASP.NET MVC 3 and ASP.NET MVC 4? Can you explain in detail?
Ans. There is large difference between the working and implementation mechanism between ASP.NET MVC 3 and ASP.NET MVC 4.

In ASP.NET MVC 3, to implement asynchronous controller/methods you need to derive controller from AsyncController rather than from plain Controller class. You need to create two action methods rather than one. Fist with suffix “Async” keyword and second with “Completed” suffix. The method which initiated asynchronous process must end with “Async” and the method which is invoked when the asynchronous process finishes must end with “Completed”. Following is example showing the same.

//Synchronous Implementation

public class SynchronousTestController : Controller

{

    public ActionResult Index()

    {

        method1();

        method2();

        return View();

    }

}

//Asynchronous Implementation in ASP.NET MVC 3

public class AsynchronousTestController : AsyncController

{

    public void IndexAsync()

    {

        method1();

        method2();

    }

    public ActionResult IndexCompleted()

    {

        return View("Index");

    }

}

The ASP.NET MVC 4 Controller class in combination .NET 4.5 enables you to write asynchronous action methods that return an object of type Task. The .NET Framework 4 introduced an asynchronous programming concept referred to as a Task and ASP.NET MVC 4 supports Task. The .NET Framework 4.5 builds on this asynchronous support with the await and async keywords that make working with Task objects much less complex than previous asynchronous approaches. The await keyword is syntactical shorthand for indicating that a piece of code should asynchronously wait on some other piece of code. The async keyword represents a hint that you can use to mark methods as task-based asynchronous methods. To implement asynchronous action method in ASP.NET MVC 4 we do no need to derive our controller class from AsyncController, async and await in cooperation with Task will do the magic. To mark the action method asynchronous use async in method signature. To wait for the other method to finish use await and to call multiple parallel methods use Task. The asynchronous method will return Task instead of plain ActionResult.

public class AsyncronousTestController : Controller

{

    public async Task<ActionResult> IndexAsync()

    {

        //if single method

        //await method();

        //if multiple methods

        await Task.WhenAll(method1(), method2());

        return View("Index");

    }

}

Here the await keyword does not block the thread execution until the task is complete. It signs up the rest of the method as a callback on the task, and immediately returns. When the awaited task eventually completes, it will invoke that callback and thus resume the execution of the method right where it left off.

16. Can you tell us some guidelines for when to use synchronous and when to use asynchronous approach?
Ans. In following situations synchronous approach is more suited.

    The operations are simple or short-running.
    Simplicity is more important than efficiency.
    The operations are primarily CPU operations instead of operations that involve extensive disk or network overhead. Using asynchronous action methods on CPU-bound operations provides no benefits and results in more overhead.

For asynchronous approach some of the guidelines are

    You’re calling services that can be consumed through asynchronous methods, and you’re using .NET 4.5 or higher.
    The operations are network-bound or I/O-bound instead of CPU-bound.
    Parallelism is more important than simplicity of code.
    You want to provide a mechanism that lets users cancel a long-running request.
    When the benefit of switching threads out weights the cost of the context switch. In general, you should make a method asynchronous if the synchronous method waits on the ASP.NET request thread while doing no work. By making the call asynchronous, the ASP.NET request thread is not stalled doing no work while it waits for the web service request to complete.
    Testing shows that the blocking operations are a bottleneck in site performance and that IIS can service more requests by using asynchronous methods for these blocking calls.

17. Which latest version of Entity Framework is included by ASP.NET MVC 4? What is the advantage of it?
Ans. ASP.NET MVC 4 is included Entity Framework 5. The main advantage of Entity Framework 5 is it’s new feature called database migration. It enables you to easily evolve your database schema using a code-focused migration while preserving the data in the database.


18. What are the provisions for real time communication in ASP.NET MVC 4?
Ans. ASP.NET MVC 4 supports WebSockets along with the new open source framework SignalR which allows to set up real time multi-user communication through open TCP sockets.

19. What is the enhancement provided related to custom controller in ASP.NET MVC 4?
Ans. In ASP.NET MVC 4 you can place custom controller to custom locations. In ASP.NET MVC 3 you can only place custom controllers inside the Controllers folder.


20 Difference Between Asp.Net Web Forms and Asp.Net MVC?

Ans



Asp.Net Web Forms
Asp.Net MVC
Asp.Net Web Form follow a traditional event driven development model.
Asp.Net MVC is a lightweight and follow MVC (Model, View, Controller) pattern based development model.
Asp.Net Web Form has server controls.
Asp.Net MVC has html helpers.
Asp.Net Web Form has state management (like as view state, session) techniques.
Asp.Net MVC has no automatic state management techniques.
Asp.Net Web Form has file-based URLs means file name exist in the URLs must have its physically existence.

Asp.Net MVC has route-based URLs means URLs are divided into controllers and actions and moreover it is based on controller not on physical file.
Asp.Net Web Form follows Web Forms Syntax.
Asp.Net MVC follow customizable syntax (Razor as default)
In Asp.Net Web Form, Web Forms(ASPX) i.e. views are tightly coupled to Code behind(ASPX.CS) i.e. logic.
In Asp.Net MVC, Views and logic are kept separately.

Asp.Net Web Form has Master Pages for consistent look and feels.
Asp.Net MVC has Layouts for consistent look and feels.
Asp.Net Web Form has User Controls for code re-usability.
Asp.Net MVC has Partial Views for code re-usability.
Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access.

Asp.Net MVC is lightweight, provide full control over markup and support many features that allow fast & agile development. Hence it is best for developing interactive web application with latest web standards.
Asp.Net Web Form is not Open Source.
Asp.Net Web MVC is an Open Source.


Read more ...

Entity Framework Question

Sunday 18 May 2014

What is Entity Framework?

Entity Framework is an additional layer between application and database that enables the developers to program against the conceptual application model instead of programming directly against the relational storage schema.

Will there be any issues adding a table without primary keys to a data model?

Every entity must have a key, even in the case where the entity maps to a view. When you use the Entity Designer to create or update a model, the classes that are generated inherit from EntityObject, which requires EntityKey. So, we have to have a primary key in the table to add it to the data model.

How do you truncate a table using entity data model?

Unfortunately Entity Framework doesn’t include anything straight forward to handle this. But we can still call a T-SQL statement using entity framework that will still minimizes the developers work. We can call ExecuteStoreCommand() methond on ObjectContext as shown below.

using (var context = new MyTestDbEntities())

{

    context.ExecuteStoreCommand("TRUNCATE table Dummy");

}

How do you query in entity model when the result has a join from from different database other than the entity model? E.g.: SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1

As the entity model doesn’t support querying from any entity other than the entities defined in Entity Data Model, we have to query aginst the data base using ExecuteStoredQuery of the context.

Following code snippet shows how to query when other databases are joined.

string query = "SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1";

using (var context = new SampleEntities())

{

  ObjectResult<DbDataRecord> records = context.ExecuteStoreQuery<DbDataRecord>(query);

  foreach (DbDataRecord record in records)

  {

    //Do whatever you want

  }

}

What is minimum requirement for Entity Framework applications to run?

The Entity Framework is a component of the .NET Framework so Entity Framework applications can run on any computer on which the .NET Framework starting with version 3.5 SP1 is installed.

What is CSDL?

Conceptual schema definition language (CSDL) is an XML-based language that describes the entities, relationships, and functions that make up a conceptual model of a data-driven application. This conceptual model can be used by the Entity Framework or WCF Data Services.

The metadata that is described with CSDL is used by the Entity Framework to map entities and relationships that are defined in a conceptual model to a data source. More=> http://msdn.microsoft.com/en-us/library/bb399292.aspx

What is SSDL?

Store schema definition language (SSDL) is an XML-based language that describes the storage model of an Entity Framework application.

In an Entity Framework application, storage model metadata is loaded from a .ssdl file (written in SSDL) into an instance of the System.Data.Metadata.Edm.StoreItemCollection and is accessible by using methods in the System.Data.Metadata.Edm.MetadataWorkspace class. The Entity Framework uses storage model metadata to translate queries against the conceptual model to store-specific commands. More=> http://msdn.microsoft.com/en-us/library/bb399559.aspx

What is MSL?

Mapping specification language (MSL) is an XML-based language that describes the mapping between the conceptual model and storage model of an Entity Framework application.

In an Entity Framework application, mapping metadata is loaded from an .msl file (written in MSL) at build time. The Entity Framework uses mapping metadata at runtime to translate queries against the conceptual model to store-specific commands. More=> http://msdn.microsoft.com/en-us/library/bb399202.aspx

What is Entity Data Model?

The Entity Data Model (EDM) is a set of concepts that describe the structure of data, regardless of its stored form. The EDM borrows from the Entity-Relationship Model described by Peter Chen in 1976, but it also builds on the Entity-Relationship Model and extends its traditional uses.

The EDM addresses the challenges that arise from having data stored in many forms. For example, consider a business that stores data in relational databases, text files, XML files, spreadsheets, and reports. This presents significant challenges in data modeling, application design, and data access. When designing a data-oriented application, the challenge is to write efficient and maintainable code without sacrificing efficient data access, storage, and scalability. When data has a relational structure, data access, storage, and scalability are very efficient, but writing efficient and maintainable code becomes more difficult. When data has an object structure, the trade-offs are reversed: Writing efficient and maintainable code comes at the cost of efficient data access, storage, and scalability. Even if the right balance between these trade-offs can be found, new challenges arise when data is moved from one form to another. The Entity Data Model addresses these challenges by describing the structure of data in terms of entities and relationships that are independent of any storage schema. This makes the stored form of data irrelevant to application design and development. And, because entities and relationships describe the structure of data as it is used in an application (not its stored form), they can evolve as an application evolves. More=> http://msdn.microsoft.com/en-us/library/ee382825.aspx

Which are the key concepts of Entity Data Model?

The Entity Data Model (EDM) uses three key concepts to describe the structure of data: entity type, association type, and property. These are the most important concepts in describing the structure of data in any implementation of the EDM.

1. Entity Type: The entity type is the fundamental building block for describing the structure of data with the Entity Data Model. In a conceptual model, entity types are constructed from properties and describe the structure of top-level concepts, such as a customers and orders in a business application.

2. Association Type: An association type (also called an association) is the fundamental building block for describing relationships in the Entity Data Model. In a conceptual model, an association represents a relationship between two entity types (such as Customer and Order).

3. Property: Entity types contain properties that define their structure and characteristics. For example, a Customer entity type may have properties such as CustomerId, Name, and Address. More=> http://msdn.microsoft.com/en-us/library/ee382840.aspx

What is .edmx file and what it contains?

An .edmx file is an XML file that defines a conceptual model, a storage model, and the mapping between these models. An .edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.

How can you tell EF to have a different table or column name than that defined for the class?

By convention, EF defines the table and column names based on your class and property names.

You can use the [Table] and [Column] annotations to tell EF to use different names.
How do you mark a property as required? For example, For a Project, the Name is a required field.

You use the [Required] attribute to mark a property as required.

What is use of EntityDataSource Control?

The ADO.NET EntityDataSource control supports data binding scenarios in Web applications that use the ADO.NET Entity Framework. Like the Entity Framework, the control is available as part of the .NET Framework 3.5, beginning with SP1. Like the other Web server data source controls, the EntityDataSource control manages create, read, update, and delete operations against a data source on behalf of data-bound controls on the same page. The EntityDataSource works with editable grids, forms with user-controlled sorting and filtering, dually bound drop-down list controls, and master-detail pages.

What is Model First Approach?

A new Model First approach was supported in Visual Studio 2010, which was released together with the second Entity Framework version (Entity Framework v4). In Model First approach the development starts from scratch. At first, the conceptual model is created with Entity Data Model Designer, entities and relations are added to the model, but mapping is not created.

After this Generate Database Wizard is used to generate storage (SSDL) and mapping (MSL) parts from the conceptual part of the model and save them to the edmx file. Then the wizard generates DDL script for creating database (tables and foreign keys)

If the model was modified, the Generate Database Wizard should be used again to keep the model and the database consistent. In such case, the generated DDL script contains DROP statements for tables, corresponding to old SSDL from the .edmx file, and CREATE statements for tables, corresponding to new SSDL, generated by the wizard from the conceptual part. In Model First approach developer should not edit storage part or customize mapping, because they will be re-generated each time when Generate Database Wizard is launched.

What is Code First Approach?

Code First allows you to define your model using C# or VB.Net classes, optionally additional configuration can be performed using attributes on your classes and properties or by using a Fluent API. Your model can be used to generate a database schema or to map to an existing database. More=>http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx

What is Entity SQL?

Entity SQL is a SQL-like storage-independent language, designed to query and manipulate rich object graphs of objects based on the Entity Data Model (EDM). More=>http://msdn.microsoft.com/en-us/library/bb399560(v=vs.90).aspx

What is LINQ To Entities?

LINQ to Entities provides Language-Integrated Query (LINQ) support for querying entities.

LINQ to Entities enables developers to write queries against the database using one of the supported .NET Framework programming languages such as Visual Basic or Visual C#.

What is EntityClient? System.Data.EntityClient is a storage-independent ADO.NET data provider that contains classes such as EntityConnection, EntityCommand, and EntityDataReader. Works with Entity SQL and connects to storage specific ADO.NET data providers, such as SqlClient. More=>http://msdn.microsoft.com/en-us/library/bb738561(v=vs.90).aspx

What is Deferred Loading(Lazy Loading)?

When objects are returned by a query, related objects are not loaded at the same time.

Instead they are loaded automatically when the navigation property is accessed. Also known as “lazy loading,”

What is Eager Loading?

The process of loading a specific set of related objects along with the objects that were explicitly requested in the query. More=>http://msdn.microsoft.com/en-us/library/bb896272(v=vs.90).aspx

What is Complex Type?

A .NET Framework class that represents a complex property as defined in the conceptual model. Complex types enable scalar properties to be organized within entities. Complex objects are instances of complex types. More=>http://msdn.microsoft.com/en-us/library/bb738472(v=vs.90).aspx

What is Conceptual Model?

An implementation of the Entity Data Model (EDM), specific to the Entity Framework, which represents an abstract specification for the data structures that define an entity-relationship representation of data in the domain of an application. More=>http://msdn.microsoft.com/en-us/library/bb399183(v=vs.90).aspx

What is use of Entity Container?

Specifies entity sets and association sets that will be implemented in a specified namespace. More=>http://msdn.microsoft.com/en-us/library/bb399557(v=vs.90).aspx

What is Explicit Loading?

When objects are returned by a query, related objects are not loaded at the same time. By default, they are not loaded until explicitly requested using the Load method on a navigation property.



Read more ...

WCF Interview Question

Saturday 22 March 2014
What is WCF?
Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types.

WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it. WCF is Microsoft’s unified programming model for building service-oriented applications with managed code. It extends the .NET Framework to enable developers to build secure and reliable transacted Web services that integrate across platforms and interoperate with existing investments.

Windows Communication Foundation combines and extends the capabilities of existing Microsoft distributed systems technologies, including Enterprise Services, System.Messaging, Microsoft .NET Remoting, ASMX, and WSE to deliver a unified development experience across multiple axes, including distance (cross-process, cross-machine, cross-subnet, cross-intranet, cross-Internet), topologies (farms, fire-walled, content-routed, dynamic), hosts (ASP.NET, EXE, Windows Presentation Foundation, Windows Forms, NT Service, COM+), protocols (TCP, HTTP, cross-process, custom), and security models (SAML, Kerberos, X509, username/password, custom).

What is SOAP?
Short for Simple Object Access Protocol, a lightweight XML -based messaging protocol used to encode the information in Web Service request and response messages before sending them over a network. SOAP messages are independent of any operating system or protocol and may be transported using a variety of Internet protocols, including SMTP,MIME and HTTP.

What is service and client in perspective of data communication?
A service is a unit of functionality exposed to the world. The client of a service is merely the party consuming the service.

What is End point ?
Every service must have Address that defines where the service resides, Contract that defines what the service does and a Binding that defines how to communicate with the service. In WCF the relationship between Address, Contract and Binding is called Endpoint.

The Endpoint is the fusion of Address, Contract and Binding.

What is endpoint in WCF? or What is three major points in WCF?
Every service must have Address that defines where the service resides, Contract that defines what the service does and a Binding that defines how to communicate with the service.

In WCF the relationship between Address, Contract and Binding is called Endpoint. The Endpoint is the fusion of Address, Contract and Binding.

1. Address : Specifies the location of the service which will be like http://Myserver/MyService.Clients will use this location to communicate with our service.

2. Contract : Specifies the interface between client and the server.It’s a simple interface with some attribute.

3. Binding : Specifies how the two party will communicate in term of transport and encoding and protocols.


Why do we need  WCF?
There is one main Bank system which is directly connected with the database, that provides other systems like ATM machine, Loan System data using various communication protocols like Remoting, web service, etc. For communicating with different Systems using different communication protocols, you have to know the API of that technology. In WCF, you have to just make different End points for different services. There is no need to learn a different API. You can use only one common API for communication with different System.
In WCF, you have to just make different End points for different services. There is no need to learn a different API. You can use only one common API for communication with a different System.
Sample Image - maximum width is 600 pixels
Sample Image - maximum width is 600 pixels

What is binding and how many types of bindings are there in WCF?
A binding defines how an endpoint communicates to the world. A binding defines the transport (such as HTTP or TCP) and the encoding being used (such as text or binary).

A binding can contain binding elements that specify details like the security mechanisms used to secure messages, or the message pattern used by an endpoint.

WCF supports nine types of bindings.

1. Basic binding :
Offered by the BasicHttpBinding class, this is designed to expose a WCF service as a legacy ASMX web service, so that old clients can work with new services. When used by the client, this binding enables new WCF clients to work with old ASMX services.

2. TCP binding :

Offered by the NetTcpBinding class, this uses TCP for cross-machine communication on the intranet. It supports a variety of features, including reliability, transactions, and security, and is optimized for WCF-to-WCF communication. As a result, it requires both the client and the service to use WCF.

3. Peer network binding :
Offered by the NetPeerTcpBinding class, this uses peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast messages to it.

4. IPC binding :
Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding.

5. Web Service (WS) binding :
Offered by the WSHttpBinding class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet.

6. Federated WS binding :

Offered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security.

7. Duplex WS binding :
Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client.

8. MSMQ binding :

Offered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls.

9. MSMQ integration binding :

Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.

What is contracts in WCF?
In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does.

WCF defines four types of contracts.
1. Service contracts : Describe which operations the client can perform on the service.

2. Data contracts : Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.

3. Fault contracts : Define which errors are raised by the service, and how the service handles and propagates errors to its clients.

4. Message contracts : Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.

What is address in WCF and how many types of transport schemas are there in WCF?
Address is a way of letting client know that where a service is located. In WCF, every service is associated with a unique address. This contains the location of the service and transport schemas. 

WCF supports following transport schemas
1. HTTP
2. TCP
3. Peer network
4. IPC (Inter-Process Communication over named pipes)
5. MSMQ

The sample address for above transport schema may look like

http://localhost:81
http://localhost:81/MyService
net.tcp://localhost:82/MyService
net.pipe://localhost/MyPipeService
net.msmq://localhost/private/MyMsMqService
net.msmq://localhost/MyMsMqService

What is the difference WCF and Web services?
1. Web services can only be invoked by HTTP. While Service or a WCF component can be invoked by any protocol and any transport type.

2. Second web services are not flexible. But Services are flexible. If you make a new version of the service then you need to just expose a new end point. So services are agile and which is a very practical approach looking at the current business trends.

How can we host a service on two different protocols on a single server?
Let’s first understand what this question actually means. Let’s say we have made a service and we want to host this service using HTTP as well as TCP.

You must be wondering why to ever host services on two different types of protocol. When we host a service it’s consumed by multiple types of client and it’s very much possible that they have there own protocol of communication. A good service has the capability to downgrade or upgrade its protocol according the client who is consuming him.

Let’s do a small sample in which we will host the ServiceGetCost on TCP and HTTP protocol.

Once we are done the server side coding its time to see make a client by which we can switch between the protocols and see the results. Below is the code snippet of the client side for multi-protocol hosting

What are various ways of hosting WCF?

There are three major ways of hosting a WCF services:
  • Self-hosting the service in its own application domain. The service comes into 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.
How does WCF work?
Follows the ‘software as a service’ model, where all units of functionality are defined as services.

A WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal (connection) for communication with either clients (applications) or other services.

Enables greater design flexibility and extensibility of distributed systems architectures.

A WCF application is represented as a collection of services with multiple entry points for communications.

What are the main components of WCF?
1.Service: The working logic or offering, implemented using any .Net Language©.

2.Host:
 The environment where the service is parked. E.g. exe, process, windows service

3.Endpoints: The way a service is exposed to outside world.

Explain transactions in WCF.
Transactions in WCF allow several components to concurrently participate in an operation. Transactions are a group of operations that are atomic, consistent, isolated and durable. WCF has features that allow distributed transactions. Application config file can be used for setting transaction timeouts.

What are different isolation levels provided in WCF?
The different isolation levels:

1. READ UNCOMMITTED: – An uncommitted transaction can be read. This transaction can be rolled back later.

2. READ COMMITTED :-
 Will not read data of a transaction that has not been committed yet

3. REPEATABLE READ: – Locks placed on all data and another transaction cannot read.

4. SERIALIZABLE:- Does not allow other transactions to insert or update data until the transaction is complete.

How do I serialize entities using WCF?
LINQ to SQL supports serialization as XML via WCF by generating WCF serialization attributes and special serialization specific logic during code-generation. You can turn on this feature in the designer by setting serialization mode to ‘Unidirectional’. Note this is not a general solution for serialization as unidirectional mode may be insufficient for many use cases.

Read more ...

Sharing

Get widget