WCF Interview questions:
- What is WCF?
- Why to use WCF and the advantages of using WCF?
- What are the new features introduced in WCF 4.5?
- What is the difference between WCF and ASMX Web services?
- What are the core components of WCF Service?
- What are the Endpoints in WCF? or Explain ABCs of endpoint?
- What is a WCF Binding? How many different types of bindings available in WCF?
- What is WebHttpBinding in WCF?
- What is the difference between basicHttpBinding or wsHttpBinding?
- Can we have multiple endpoints for different binding types in order to serve different types of clients?
1. What is WCF?
- WCF stands for Windows communication Foundation.
- It is a Microsoft platform for building distributed and Interoperable applications.
- It is a framework for building service oriented applications
- Microsoft has unified all its existing distributed application technologies (e.g. MS Enterprise Services, ASMX web services, MSMQ, .NET Remoting etc) at one platform i.e. WCF
You can read more on this here.
2. Why to use WCF and what all are the advantages of using WCF?
For an example we have 2 clients. The first client is using a Java application to interact with our service, so the clients wants messages to be in XML and the protocol to be HTTP.
So without WCF, we will create a asmx service and it supports both HTTP and XML messaging to suffice the client requirement.
Whereas the second client wants us to send binary message and TCP protocol. To suffice the requirement we will end up writing remoting services.
Remoting service has a different programming model, so we want our developers to learn remoting services to suffice the client requirement.
So for both client we will end up creating 2 services.web service and remoting service. This is the reason, Microsoft came up with WCF to unify remoting, enterprise services ,webservices etc.
In WCF, we can create one common WCF service and expose multiple endpoints to suffice different message format and protocols for the clients.
In the configuration file, we can define the protocols and message format for the clients.
3. What all are the new features introduced in WCF 4.5?
- Simplified Generated Configuration files, generated configuration file on client will only have non-default binding configuration.
- Validating WCF Configuration is now part of v4.5. While compiling if there are some validation errors with configuration file, it will be displayed as warnings in Visual Studio.
- WCF 4.5 support for Task-based Asynchronous programming model.
- Contract First Development is now supported. Only contract will be generated in service.cs, if we use SvcUtil.exe with “/ServiceContract” switch while generating proxy.
- ASP.NET Compatibility Mode changed to enable WCF service to participate in ASP.NET Pipeline just like ASMX services.
- Tooltip and intellisense support in Configuration files.
- XmlDictionaryReaderQuotas default values has been changed.
- v4.5 allows to create an endpoint that supports Multiple Authentication Types.
- Automatic HTTPS endpoints in IIS.
- Improvements in Streaming, support for real asynchronous streaming, no blockage of one thread per client as with previous versions.
- Support for UDP transport, using UDP one way messages are very fast.
- BasicHttpsBinding, new security configuration option.
- In order to have bidirectional communication with better performance like TCP,WebSocket is the right choice.
- WCF v4.5 introduces NetHttpBinding and NetHttpsBinding bindings for supporting WebSockets.
- Single WSDL Document, now we can create WSDL information in one file.
- IDN (Internationalized Domain Names) support means WCF Service can be called using IDN names by client.
- Compression support is now available for Binary Encoder in WCF 4.5 through CompressionFormat property.
- ChannelFactory Cache, WCF 4.5 now support for caching Channel Factories to reduce overhead associated while creating a ChannelFactory instance.
- WCF Service can be configured using config file or through code. In v4.5, configuration through code has been simplified by defining a public static method (i.e. configure) instead of creating a ServiceHostFactory.
4. What is the difference between ASMX and WCF webservices?
Simple and basic difference is that ASMX web service is designed to send and receive messages using SOAP over HTTP only. While WCF service can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc)
You can read more detailed difference here.
5. What are the core components of WCF Service?
WCF service has 3 core components.
Service Class: A service class implementing in any CLR-based language and expose at least one method.
Hosting Environment: a managed process for running service.
Endpoint: a client uses it to communicate with service.
6.What are the Endpoints in WCF? or Explain ABCs of endpoint?
The endpoint is the fusion of the address, contract, and binding. Every endpoint must have all three elements, and the host exposes the endpoint.
- Address: It defines “WHERE”. Address is the URL that identifies the location of the service.
- Binding: It defines “HOW”. Binding defines how the service can be accessed.
- Contract: It defines “WHAT”. Contract identifies what is exposed by the service.
7. What is a WCF Binding? How many different types of bindings available in WCF?
A WCF binding defines how the client needs to communicate with the service.
A WCF service endpoint consists 3 things.
A – Address : Address for the WCF service
B – Binding : How the Client needs to communicate with the service
C – Contract : Defines what the service can do
DIfferent types of bindings available in WCF:
You can read more on WCF binding here.
8. What is WebHTTPBinding in WCF?
WebHttpBinding is the one that is used for creating WCF RESTful services.
Reference books, you may like:Programming WCF Services: Design and Build Maintainable Service-Oriented Systems
WCF Multi-Layer Services Development with Entity Framework, 4th Edition
Learning WCF: A Hands-on Guide
In Windows Communication Foundation v3.5, Microsoft introduces support for building RESTful services.
REST (Representational State Transfer) is an architectural design that uses HTTP the way it should be used.
Instead of using HTTP just as a transport (in case of SOAP-based WCF Services), RESTful WCF services uses full features of HTTP (for all CRUD Operations including Create, Retrieve, Update and Delete).
9. What is the difference between BasicHttpBinding and WSHTTPBinding?
Microsoft Windows Communication Foundation comes with a set of built-in bindings and each binding is designed to fulfill some specific need. So, if interoperability is our concern and we need to communicate with non-WCF system, then, we should go for basicHttpBinding or wsHttpBinding.
|Primarily BasicHttpBinding is designed to exchange SOAP over HTTP(s) only, just like old ASMX or .net web services and supports the WS-I BasicProfile.||WsHttpBinding supports the advanced WS-* specification which includes WS-Addressing and WS-Security etc.|
|It has higher level of interoperability with existing services and clients.||Due to more advanced messaging scenarios, it has reduced support for wider range of older clients.|
|BasicHttpBinding is based on SOAP 1.1 specification.||WsHttpBinding supports SOAP 1.2 specification.|
|No support for reliable Messaging.||Supports for reliable messaging.|
|No support for transactions.||It supports atomic and distributed transactions.|
|It has fewer security options. Or we can say, there is no security provided, by default, for BasicHttpBinding.||Because WsHttpBinding supports advanced WS-* specification, it has a lot more security options available. For example, It provides message-level security i.e. message is not sent in plain text. Also it supports for WS-Trust and WS-Secure conversation.|
|At transport level, it provides support for confidentiality through SSL.||It supports for both Transport as well as Message level security.|
|BasicHttpBinding is a bit faster because security is disabled by default.||As it supports advanced security options and its enabled by default, so it’s a bit slower than BasicHttpBinding.|
10. Can we have multiple endpoints for different binding types in order to serve different types of clients?
Yes, we can have multiple endpoints for different binding types. For example, an endpoint with wsHttpBinding and another one with netTcpBinging.
© 2015, admin. All rights reserved.