WCF Interview Questions and Answers
Question - 21 : - With WCF can one communicate with other non-Microsoft applications also?
Answer - 21 : - Yes, one can communicate with other non-Microsoft applications like J2EE as well.
Question - 22 : - State the three main components of WCF.
Answer - 22 : - The three main components of WCF are as follows… endpoints, hosting environment and service class.
Question - 23 : - What is the model of functionality that WCF follows?
Answer - 23 : - The model of functionality that WCF follows is… software as a service.
Question - 24 : - How does software as a service work?
Answer - 24 : - The way this model works is that each point is a source of connecting either with a client or with any other services involved. Thus as a program, it shows a collection of endpoints.
Question - 25 : - What are the WCF service endpoints?
Answer - 25 : - WCF service endpoint has three basic elements: address, binding, and contract.
Address: It defines the address of the URL that identifies the location of the service and specifies the location where messages are received. It is specified as a Uniform Resource Identifier (URI). The URI schema part names the transport mechanism to use to reach the address, such as HTTP and TCP. The hierarchical part of the URI contains a unique location whose format is dependent on the transport mechanism.
The endpoint address enables you to create unique endpoint addresses for each endpoint in service or, under certain conditions, to share an address across endpoints. The following example shows an address using the HTTPS protocol with a non-default port:
https://cohowinery:8005/ServiceModelSamples/CalculatorService
Binding: It defines how the service can be accessed, how an endpoint communicates to the world. It is constructed of a set of components called binding elements that "stack" one on top of the other to create the communication infrastructure. At the very least, 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.
Contract: It defines what is exposed by the service. Ties together multiple related operations into a single functional unit. The contract can define service-level settings, such as the namespace of the service, a corresponding callback contract, and other such settings. In most cases, the contract is defined by creating an interface in the programming language of your choice and applying the ServiceContractAttribute attribute to the interface. The actual service code results by implementing the interface.
Operation contract
An operation contract defines the parameters and returns type of operation. When creating an interface that defines the service contract, you signify an operation contract by applying the OperationContractAttribute attribute to each method definition that is part of the contract. The operations can be modeled as taking a single message and returning a single message, or as taking a set of types and returning a type. In the latter case, the system will determine the format for the messages that need to be exchanged for that operation.
Message contract
Describes the format of a message. For example, it declares whether message elements should go in headers versus the body, what level of security should be applied to what elements of the message, and so on.
Fault contract
Can be associated with a service operation to denote errors that can be returned to the caller. An operation can have zero or more faults associated with it. These errors are SOAP faults that are modeled as exceptions in the programming model.
Data contract
The descriptions in metadata of the data type that a service uses. This enables others to interoperate with the service. The data types can be used in any part of a message, for example, as parameters or return types. If the service is using only simple types, there is no need to use data contracts explicitly.
Question - 26 : - What are the essential components used in WCF?
Answer - 26 : - A list of essential components used in WCF:
Service class
The service runtime layer contains the behaviors that occur only during the actual operation of the service, that is, the runtime behaviors of the service. Throttling controls how many messages are processed, which can be varied if the demand for the service grows to a preset limit.
Endpoint
WCF Service is a program that exposes a collection of the endpoints. Each Endpoint is a portal for communicating with the world. All the WCF communications are taken place through the endpoint. An endpoint consists of three components.
Hosting Environment
A service must be hosted in some process. A host is an application that controls the lifetime of the service. Services can be self-hosted or managed by an existing hosting process.
Question - 27 : - What is the "Address" property of endpoint in WCF?
Answer - 27 : - 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.
Question - 28 : - What is the "Contract" property of endpoint in WCF?
Answer - 28 : - The "Contract" property is just an interface between the client and server where client and server communicate with each other. Contracts are used to specify operations available.
Question - 29 : - What is the service?
Answer - 29 : - 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.
Question - 30 : - What is service proxy in WCF?
Answer - 30 : - 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.