Showing posts with label WCF 4. Show all posts
Showing posts with label WCF 4. Show all posts

WCF 4 Interview Questions and Answers

WCF 4 Interview Questions with Answers

WCF 4 -Windows Communication Foundataion interview questions are very important as wcf is widely used in almost all web applications today.Lets discuss some important WCF interview questions. This also includes basic as well as advanced interview questions on WCF 4.

1.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).

2.What are types of  contracts in WCF?
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

3.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.

4.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.

5.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

6.What are contracts in WCF?
The contract is a platform-neutral and standard way of describing WHAT the service does. 
WCF defines four types of contracts,
1 Service contracts
2 Data contracts
3 Fault contracts
4 Message contracts

7.What are Service contracts?
Service contracts describe which operations the client can perform on the service in scope.

There are two types of Service Contracts.
1. ServiceContract - This attribute is used to define the Interface.
2. OperationContract - This attribute is used to define the method inside Interface.

8.What are Data contracts?
Data contracts define which data types can be passed to the service and in return which data types are expected back. 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. 

There are two types of Data Contracts.
1.DataContract - attribute used to define the custom class
2.DataMember - attribute used to define the custom properties.

In case the DataMember attribute is not specified for a property in the class, the same property can't be passed to the WCF service or can be returned by the WCF service


9. What are Fault contract?
The Fault Contract is a way to communicate error information from a service to a client.

10.What is Message contract?
WCF uses SOAP message for communication and there are situations when you need more control over the SOAP message format. In that case WCF provides Message Contract to customize the message as per requirement

11.What are the Security Modes in WCF ?
The Security Modes are stated below

WCF 4 Windows Communication Foundation Tutorials




Windows Communication Foundation (WCF 4) Tutorials
  1. Windows Communication Foundation is Microsoft's next generation technology for developing distributed applications.
  2. WCF has been built to facilitate the development of service-oriented applications. The communication between loosely coupled clients and services is based on a model that uses schemas and contracts, rather than classes and types. 
  3. Schemas and contracts are independent of programming language, hosting platform, or implementation.  
  4. As a result, this model provides many benefits such as maintainability, reusability, and manageability of your code and your solution. In addition, loosely coupled services tend to model real-world systems.
  5. WCF can communicate by using Web services, so it can interoperate with other platforms that can use Simple Object Access Protocol (SOAP), such as Java 2, Enterprise Edition (Java EE).
  6. WCF also supports many of the advanced WS-* Web service standards, which can provide rich Web service communication across platforms. 
  7. WCF can be extended to use protocols other than SOAP to communicate with Web services, for example, Rich Site Summary (RSS).
  8. WCF provides low-level asynchronous operations for passing untyped primitive messages. 
  9. Higher-level services are layered on top, including typed messages, secure message exchange, reliable message exchange, transacted messaging, and queued messaging.
  10. WCF has been designed to integrate and unify existing distributed computing technologies. 
  11. It is interoperable with WSE 3.0, System.Messaging, .NET Enterprise Services, and ASMX Web services. This means that, with little or no change to code, existing applications that are built with these technologies can interoperate with WCF services

  • WCF services expose endpoints that clients and services use to exchange messages. Each endpoint consists of an address, a binding, and a contract The address identifies where the service is located on the network. The address format is protocol specific. Addresses can be specified in code or in configuration files. Configuration files are preferable, because they enable an administrator to configure addresses at deployment time.
  • The binding defines how the client needs to communicate with the service. For example, a binding defines the underlying transport protocol, security requirements, and message encoding.
  • WCF provides several standard bindings whose behaviors can be modified in configuration files.  For example, BasicHttpBinding exposes an HTTP-based WCF service that encodes SOAP messages in text format. This binding is used for interoperability. WsHttpBinding adds support for advanced Web service features, such as transactions and reliable messaging. NetMsmqBinding uses Microsoft Message Queuing, or MSMQ, as the transport.
  • The contract defines what the service can do. WCF specifies attributes that can be used to define contract types, including those that define service operations, messages, data types, and fault behavior. 
  • A service contract defines the operations that are available at the endpoint. A service contract is defined by a .NET Framework interface that has added WCF attributes.  
  • A class, called the service type, implements the interface to provide the implementation of the service operations.
  • To make your WCF services widely accessible, you can use ASP.NET and Internet Information Services, or IIS, to host HTTP-based WCF services. 
  • In addition, you can use any .NET Framework application to host your WCF services by using the ServiceHost class. 
  • The service can provide metadata about its endpoints to clients in the form of Web Service Description Language, or WSDL.
  • Client-side tools can use WSDL, to generate a proxy through which the client communicates with the service. 
  • The proxy contains a client that is capable of invoking the service contract WSDL specifies, and configuration information provides address and binding information

WCF 4 Security Modes with examples

WCF 4 Security Modes with examples
In this article i will explain the security modes in Windows Communication Foundation WCF 4.0.This security modes are an important part of WCF 
Many WCF services will require secure communication, where it is necessary to authenticate the sender of a message, and to ensure that messages have not been read or tampered with by unauthorized third parties. WCF can provide authentication, privacy, and integrity for messages by using two mechanisms

WCF Security Modes can be asked in Interview Questions.
WCF 4 Interview Questions with Answers
The Security Modes are stated below
1.Transport Mode
2.Message Mode
3.Mixed Mode
Let us now explain each one of them in details

1.Transport Mode 
Transport mode, which uses the security features of a transport layer such as HTTPS. This mode has performance benefits due to the optimized nature of the underlying protocols, but it has a restricted set of credential or claim types. This mode also only works between two transport endpoints
2.Message Mode
Message mode, which protects the message itself by using a protocol such as WS-Security. Credential information is embedded within the message so that this mode can support a richer set of claim types at the expense of performance. This mode provides end-to-end security for the message.
3.Mixed Mode 
WCF also supports a mixed mode, where integrity and privacy are provided by the transport, while authentication is handled by using credentials in the message. This can give the best balance of performance and flexibility.
You can specify the security for a binding by setting its SecurityMode property.
By default, the BasicHttpBinding has no security configured. Other HTTP bindings use WS-Security, and TCP and Named Pipe bindings use Windows security