Click here to Skip to main content
15,867,568 members
Articles / WCF

WCF FAQs - Part 1

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
27 May 2014CPOL5 min read 23.2K   17   3
A collection of most frequently asked questions about Windows Communication Foundation covering the beginner level

The article is a collection of most frequently asked questions about Windows Communication Foundation covering the beginner level.

What is WCF?

Microsoft refers to WCF as a programming platform that is used to build Service-oriented applications. Windows Communication Foundation is basically a unified programming model for developing, configuring and deploying distributed services. Microsoft has unified all its existing distributed application technologies (e.g. Microsoft Enterprise Services, ASMX web services, MSMQ, .NET Remoting, etc.) at one platform, i.e., WCF. Code name for WCF was Indigo.

Why to Use WCF? or What are the Advantages for Using WCF?

  • Service Orientation is one of the key advantages of WCF. We can easily build service-oriented applications using WCF.
  • If compared with ASMX web services, WCF service provides reliability and security with simplicity.
  • As opposed to .NET Remoting, WCF services are interoperable.
  • Different clients can interact with the same service using different communication mechanisms. This is achieved by using service endpoints. A single WCF service can have multiple endpoints. So, the developer will write code for service once and just by changing configuration (defining another service endpoint), it will be available for other clients as well.
  • Extensibility is another key advantage of WCF. We can easily customize a service behavior if required.

What are the Core Components of WCF Service?

A WCF service has at least the following 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

What is the Difference Between WCF and ASMX Web Services?

The 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, Named Pipes etc).

You can find a detailed discussion on WCF Vs ASMX Web services here.

What are the Endpoints in WCF? or Explain ABCs of Endpoint?

For WCF services to be consumed, it’s necessary that it must be exposed; Clients need information about service to communicate with it. This is where service endpoints play their role.

A service endpoint has three basic elements or also called ABCs of an endpoint, i.e., Address, Binding and Contract.

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

What is a WCF Binding? How Many Different Types of Bindings are Available in WCF?

Bindings in WCF actually define how to communicate with the service. Binding specifies what communication protocol as well as encoding method will be used. Optionally, binding can specify other important factors like transactions, reliable sessions and security.

Another WCF Tutorial gives more detailed understanding of Binding concept in WCF.

There are different built-in bindings available in WCF, each designed to fulfill some specific need.

  • basicHttpBinding
  • wsHttpBinding
  • netNamedPipeBinding
  • netTcpBinding
  • netPeerTcpBinding
  • netmsmqBinding

For details on different binding types, please follow the link to WCF bindings.

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.

What are the Hosting Options for WCF Services? Explain.

For a service to host, we need at least a managed process, a ServiceHost instance and an Endpoint configured. Possible approaches for hosting a service are:

  1. Hosting in a Managed Application/ Self Hosting
    1. Console Application
    2. Windows Application
    3. Windows Service
  2. Hosting on Web Server
    1. IIS 6.0 (ASP.NET Application supports only HTTP)
    2. Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP, NamedPipes, MSMQ

What are Contracts in WCF?

A Contract is basically an agreement between the two parties, i.e., Service and Client. In WCF, Contracts can be categorized as behavioral or structural.

  1. Behavioral Contracts define what operations client can perform on a service.
    • ServiceContract attribute is used to mark a type as Service contract that contains operations.
    • OperationContract attributes is used to mark the operations that will be exposed.
    • Fault Contract defines what errors are raised by the service being exposed.
  2. Structural Contracts
    • DataContract attribute define types that will be moved between the parties.
    • MessageContract attribute define the structure of SOAP message.

What Message Exchange Patterns are Supported by WCF?

  • Request/Response
  • One Way
  • Duplex

Request/Response

It’s the default pattern. In this pattern, a response message will always be generated to the consumer when the operation is called, even with the void return type. In this scenario, response will have empty SOAP body.

One Way

In some cases, we are interested to send a message to service in order to execute certain business functionality but not interested in receiving anything back. OneWay MEP will work in such scenarios. If we want queued message delivery, OneWay is the only available option.

Duplex

The Duplex MEP is basically a two-way message channel. In some cases, we want to send a message to service to initiate some longer-running processing and require a notification back from service in order to confirm that the requested process has been completed.

Related WCF Articles

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Emaratech
United Arab Emirates United Arab Emirates
Imran Abdul Ghani has more than 10 years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET(MCSD.NET) since 2005. You can reach his blogging at WCF Tutorials, Web Development, SharePoint for Dummies.

Comments and Discussions

 
Questiongood for beginners Pin
Soumitra Mithu30-Sep-13 20:41
professionalSoumitra Mithu30-Sep-13 20:41 
hope in part 2 some advance level question and answer will come
SuggestionVery basic Pin
Sridhar Patnayak6-Aug-12 1:13
professionalSridhar Patnayak6-Aug-12 1:13 
GeneralRe: Very basic Pin
Imran Abdul Ghani6-Aug-12 5:01
Imran Abdul Ghani6-Aug-12 5:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.