Professional Documents
Culture Documents
What Is WCF
What Is WCF
WCF stands for Windows Communication Foundation. It is a framework which is used for building, configuring and deploying interoperable distributed services. It provides a facility to
write more secure flexible services without any code change. It also provides built-in support for logging. It facilitates you for enable/disable logging using configuration.
WCF service endpoint has three basic elements: address, binding and contract.
o Address: It defines the address of the URL that identifies the location of the service.
o Service class
o End point
o Hosting Environment
The "Address" property is the part of endpoint defined in service level. This property is used to specify the location where the service is located.
The "Binding" property is the part of endpoint defined in service level. This property is used to specify the type protocols, encoding's and transport.
The "Contract" property is just an interface between client and server where client and server communicate each other. Contracts are used to specify operations available.
7) What is service?
A service is a set of functionality exposed to the world. Service orientation (SO) is an abstract set of principles and best practices for building service-oriented applications.
WCF Proxies are used to communicate between client and server. The communication takes place by exchanging the messages in the form of requests and responses. It will have the
details like Service Path, Protocol details and so on.
The Service Contracts attribute is used at the service level for WCF service. It provides the list of operations that can be performed from that service.
[ServiceContract]
o Per Call
o Singleton
o Per Session
When a request has made to service, it creates a new instance of service for each method call and this will be disposed once the response goes to client. This whole process is known as
per call instance mode.
Per session instance mode creates a logical session between service and client and it will be maintained till the end of the session. When client requests from service the session will be
created and it is dedicated to instance for that client and it will going to end when client session ends.
In "Singleton" mode all the clients are connected to the single instance of the service and when service configured for "Singleton" mode, instance will be created when service is hosted
and it will be disposed once its shuts down.
14) What do you mean by client?
The client of a service is the program unit consuming its functionality. A client can be anything like Console application, Windows form, WPF or Silverlight class or ASP.Net page etc.
WCF follows the model "Software as a Service". In this model all units of functionality are defined as services and for communication, each point is a portal or connection either with the
client or other services. It is a program that exposes a collection of endpoints.
16) What is the difference between ASMX web services and WCF?
The main difference between WCF and ASMX web service is that ASMX is designed to send and receive messages using SOAP over HTTP only while WCF facilitates you to send and
receive messages using any format over any transport protocol.
o Service Contracts
o Data Contracts
o Fault Contracts
o Message Contracts
You need at least a managed process, a ServiceHost instance and an Endpoint configured for hosting a WCF service.
o Console Application
o Windows Application
o Windows Service
o Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP, NamedPipes, MSMQ.
19) Which are the different isolation levels in WCF?
o Read Committed
o Read Uncommitted
o Serializable
o Repeatable Read
WCF RIA is the framework for developing n-tier application for RIA (Rich Internet App). It is used in Rich Internet Apps like Silverlight, AJAX etc. WCF RIA is used to solve the major
problems like Tight Coupling.
o Using SvcUtil
Binding is used to define how an endpoint communicates to the world. It defines the transport such as HTTP or TCP. It can contain binding elements that specify details like the security
mechanisms used to secure message patterns used by an end point.
o One-Way
o Request-Reply
o Callback
25) What is request-reply mode in WCF?
When a client made a request to a service, it will wait until it gets the response back.
o If the response is not received till the given time, it will show an error.
o Basic binding
o TCP binding
o IPC binding
o Duplex WS binding
o MSMQ binding
o HTTP
o TCP
o PEER network
o MSMQ
o IIS
o Self-Hosting
In WCF we can communicate with server from our client through message. So messages will be going to and fro between server and client. For security purpose we are serializing the
messages sent across the wire.
"[DataContact]" attribute given at class level to serialize the class by using "[Datamember]" attribute over properties.
DataContractSerializer is introduced in .NET 3.0 and WCF uses DataContractSerializer as default one. But now this serializer can be used for other serialization purposes also. For
serialization "WriteObject()" method is used.
For example:
DataContractSerializer(typeof(MyTestClassType));
32) How would you enable the metadata information of the service?
o For Default Endpoint: <serviceMetadata> tag is used in web.config file without specifying the endpoint.
o For Custom Endpoint: <serviceMetadata> tag is used in web.config file with specifying the defined endpoint.
o mexHttpBinding
o mexNamedPipeBinding
o mexHttpsBinding
o mexTcpBinding
34) How can you test a WCF application without creating client application?
There is a tool called - "wcftestclient.exe" used for testing the WCF service without creating a client application. This tool can be opened from visual studio command prompt.
35) What is transport and message reliability?
Transport reliability: It offers point-to-point guaranteed delivery at the network packet level, as well as guarantees the order of the packets.
Message reliability: It deals with reliability with message level independent of how many packets are required to deliver the message.
"Transport Reliability" specifies the guarantee of delivering packets over network as protocol TCP does. It also maintains the order of the packets as well as delivering of packets.
SOA stands for Service Oriented Architecture. It is a collection of services that determines how the communication is possible between two computing entities to achieve certain
business functionality and also how one entity can work on the behalf of other entity.
The recieveTimeout property is used to get/set the time interval to makes a connection active.
SvcUtil is a command line utility. YOu should write the following command to generate proxy:
o RPC style: In RPC style we can use the serialize types and it provides the feature that are available for local calls.
o Message style: In message style WCF allows the message header to be customized and it also allows us to define the security for body and header messages.
In WCF one way mode, client sends a request to the server but does not wait till the response comes. It does not care if the request is failed or succeeded. Client will not be blocked in
this case till it receives the response.
42) What is Callback mode in WCF? Explain.
Ans: The WCF callback mode is a special type of mode where WCF on call back calls the method of client and in this scenario WCF service acts like a client and client acts like a service.
43) What are the different types of transaction managers supported by WCF?
o Light Weight
o WS-Atomic Transaction
o OLE Transaction
MEP stands for Message Exchange Pattern. There are three types of Message Exchange Patterns are allowed:
o Data Gram
o Duplex
In WCF, "Throttling" is used to limit the sessions or instances to be created at application level. It is used to boost the performance.
The "maxConcurrentCalls" attribute in throttling is used to limit the total number of calls which are going to the service instances. Its default value is 16.
1. [KnownType(typeof(TestClassCar))]
2. [KnownType(typeof(TestClassTruck))]
3. [DataContract]
4. public class TestClassVehicle
5. {
6. }
7. [DataContract]
8. public class TestClassCar : TestClassVehicle
9. {
10. }
11. [DataContract]
12. public class TestClassTruck : TestClassVehicle
13. {
14. }