Sunday, 5 March 2017

WCF interview question Part 2

1. Ques: What is Contract in wcf ? How many types of contract ?
Answer:
Contract is a standard way of describing what the service does

Service Contract
 It describes operations exposed by the service. It can also describe message exchange pattern. Service Contract can be defined using [ServiceContract].

Operation Contract
 It defines the parameters and return type of an operation. An operation contract can also defines operation-level settings

Data Contract
it describes the format of your data and defines how data should be serialized/deserialized. A data contract can be used by an operation contract as a parameter or return type, or it can be used by a message contract to define elements.

Message Contract
Message Contract gives us a control over a SOAP message. If you use just data contract, all the data will be in SOAP message body, but if you need a control/access to SOAP message header you can use MessageContract. Message contract can be applied to type using MessageContract attribute.

Fault Contract
Fault Contract provides documented view for error accorded in the service to client. WCF handles it and conveys the error message to the client using SOAP Fault Contract.

2. Ques: How to manage Session Management in WCF ?
Answer:
WCF manage session by creating the instance of the service class. These created instance(s) handle the incoming service request
there are three way Instance Management

Per Call:
In this each request is served by a new service instance. A new service instance is created for each request and destroyed after the request is served.

Per Session:
In this each and every client requests are served by a new single service instance. It means a new service instance is created for a client all requests and destroyed after the client finished its activity.

Single:
In this all clients’ requests are served by a single service instance. It means a single service instance is created to handle all the clients’ requests and never destroyed after serving the request.

3. Ques: What is Message Exchange Patterns in WCF ? How many type of Message Exchange Pattern.
Answer:
Message Exchange Pattern (MEP) provides a way of communication between client and server in wcf.The communication between client and server are done in form of messages. When we send a message as request and get a message as response from the service.

In wcf three type of Message Exchange Pattern:
Request-Response :
This is the default message exchange pattern. client sends the request message to the service and wait for the response message from the service. The default receive timeout period is one minute. If the service does not responded to the client then the client receives a TimeoutException after one minute

One-Way:
In this client sends request message to the service and does not wait for response message from service. In this service does not sends back any response message even if any communication error occurs.

Duplex:
In this the client and services can communicate to each other with using one-way or request-response messages. This pattern use two types of contract, ServiceContract and CallbackContract for its implementation.


4. Ques: What is the difference between WCF  and web services? 
Answer:

Windows Communication Foundation : (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. It is framework to make inter-process communication easier like web services, Remoting, MS Message Queuing,
  • It can be hosted in many form like IIS, windows activation service, Self-hosting, Windows service 
  • One-Way, Request-Response, Duplex are different type of operations supported in WC.
  • System.Runtime.Serialization namespace is used for serialization.
  • Can be accessed through HTTP, TCP, Named pipes, MSMQ, Pear to pear .
  • Supports multi-threading by using ServiceBehaviour class.
  • Security, Reliable messaging, Transactions.
  • WCF are faster than Web Services.
  • Supports various protocols like HTTP, HTTPS, TCP, Named Pipes and MSMQ.
  • ServiceContract and OperationContract attributes are used for defining WCF service.

Web Services: A Web Service is programmable application logic accessible via standard web protocols. One of these web protocols is the Simple Object Access Protocol (SOAP).

  • It can be hosted in IIS Only.
  • One-way, Request- Response are the different operations supported in web service.
  • System.Xml.serialization name space is used for serialization.
  • Can be accessed through HTTP, TCP, Custom.
  • Support security but is less secure as compared to WCF.
  • Web Services are slower than WCF.
  • Doesn’t support multi-threading.
  • Supports only HTTP, HTTPS protocols.
  • WebService and WebMethod attributes are used for defining web service.

No comments:

Post a Comment

Thank you for comment