Tuesday, August 27, 2013

WCF Thing's To Remember

Ref: http://www.codeproject.com/Articles/28892/Asp-Net-Interview-Question-Part-1#Howdoweassignpagespecificattributes

1) What is WCF?

It is the unification of all the .net technologies.It is mainly used to solve the problem of  using several different technologies into one application.

2) What are the technologies it uses?

.NET Remoting ( If a system is using distributed architecture and All the client's are based on the windows platform and hosted on windows platform)

Web Services (If a system is using distributed architecture and Clients using different OS's(Non Microsoft OS and Microsoft Os)  to connect to the distributed application)

MSMQ (To improve  a system with Queue facility to solve synchronous processing problems. )

COM+(To implement package handling mechanisms)

3) WCF Based on which architecture?

It is based on the SOA (Service Oriented Architecture)

4) What are the important concepts behind the SOA?

Boundaries are well defined
  • The client who is consuming the service does not need to know how the implementation of the service is done.
  • In SOA the rule is if you do enhancement you do not need to change anything at the client. 
  • SOA based application only understands that there is an end point, contract and bindings.
Services evolve(expand gradually)
  • When the services are changing,it will not impact on the services who are consuming the current version of application.
  • In SOA services can be versioned and you can host those services in new end points.
Services share only Schemas and Contracts
  • Services use Schemas to represent data 
  • Services use contracts to understand behavior. 
  • XML is used to define schemas and contracts.(Reduce heavy coupling with server and clients)
  • They do not use language dependent types or classes in order to understand data and behavior.
Service compatibility is Policy based
  • Policy describes the capabilities of the system.
  • Depending on policies the service can degrade to match the service for the client.


5) Why we cannot say Web Services are Policy based?

Because web services are lack of Policy based service compatibility.

6) WCF over WebServise Advantage

In a WebService
It can only be server with HTTP communication channel and SOAP message. (disadvantage)
but in WCF you server with different channels.(ex Remoting,ASMX, MSMQ...)


 7) What are the core technologies of SOA?
  1. End Point
  2. Contract
  3. Address 
  4. Bindings

8) What is a End Point?(ABC)

 Every service must expose one or more end points by which the service can be available to the client.

 9) What are the important things inside a End Point.(ABC)
  1. Where  (Address)
  2. What (Contract)
  3. How (Binding)
 10) What is a Contract(What)?

Contract is an agreement between two or more parties.
It defines the protocol(set of rules) how client should communicate with your service.
Technically it describes parameters and return values for a method.

11) What is a Address(Where)?

An Address indicates where we can find this service.
Address is a URL which points to the location of the service.


12) What is Binding(How)?

Bindings determine how this end point can be accessed.
It determines how communications is done.ex:(SOAP over HTTP or BINARY over TCP)
So for each of these communications medium two bindings will be created.


13) Summery of Client Connect to a Web Service.

Client can sending requests
    on ADDRESS :"www.Address.com"
    BINDING : using HTTP
    and adhearing to CONTACT : "InterfaceName" interface

14) Which specifications does WCF follow?

WCF supports specifications defined by WS-* specifications.

15) What is the meaning of WS-* specifications?

WS-* specifications are defined together by Microsoft, IBM, SUN and many other big companies so that they can expose there service through a common protocol

16) What are the WS-* specifications?
Need to know what WS-* specification are supported by WCF and its advantages with respect to interacting with other languages.

 Messaging (WS-Addressing):- 
  • SOAP is the fundamental protocol for web services.
  • WSAddressing add extra things to SOAP headers to optimize the performance.
  • It is called as MTOM ( Message Transmission Optimization Mechanism).
  • It uses SOAP messages in XML-Binary formant using XML optimized packaging (XOP) to improve the performance. 
Security (WS-Security, WS-Trust and WS-SecureConversation):- 
  • All the three WS- define authentication, security, data integrity and privacy features for a service.
     
Reliability (WS-ReliableMessaging):- 
  • This specification ensures end-to-end communication.

Transactions (WS-Coordination and WS-AtomicTransaction):-
  • These two specifications enables transaction with SOAP messages.

Metadata (WS-Policy and WS-Metadataexchange):- 
  • WSDL is a implementation of WSMetadataExchange protocol. 
  • WS-Policy defines more dynamic features of a service which can not be expressed by WSDL.


16) What are the main Components of WCF?

Needs to define 3 main components in WCF. 

1. Service Class
2. Hosting Environment
3. End Point
  


17) What is a Service Class/Interface?

The class/interface which has to be exposed to the external client.

Use "ServiceContract" attribute to mark it as the service class/interface.


18) What is a Service Contract attribute?

It define which application interface will be exposed as a interface.

19) Reason to use an Interface as a Service over a Class?

It’s not essential that you need to use an interface you can also use a simple class and mark it as Service

but interface represent a contract and do not have implementation. (very higher level of abstraction.)

It is a good design practice to use a interface as a service.

20) What is a Operation Contract  attribute and Why we use it?

It dictates what methods should be exposed to the external client using the service.

21)What is a Data Contact attribute and Why we use it?

In all the method calls from the service class will involve some kind of a data transfer between client and server.

This attribute defines defines which type of complex data will be exchanged between client and server.

and most importantly it determine which parameters to be serialized.

22) Types that need to mark with Data Contract?

Note: - In interviews need to say that Data Contract define how the
data will be serialized during transmission.



When we using simple data types(int,bool,etc...), it is not necessary to mark them with the data contract attribute

Because we can always find matching types on the client machine.

But for complex data types we need to define this attribute.

This Data Contract defines how this data will be passed during the transmission.(How data serialized and transmit)   

 23) What namespace is used to with Data Contract?

As data contract are all about serialization you need to import System.Runtime.Serialization
name space.


24) Main things behind Hosting a WCF service?

  • Config file 
  • Hosting code is start-up.  
25) What are the various ways of hosting a WCF service?
  • Self Hosting
  • Host in application domain or process provided by IIS.
  • Host in application domain and process provided by WAS(Windows Activation Server)

26) Self Hosting

 Use App.config file

In the configuration section in App.config file

add a new section <system.serviceModel

(it has the endpoint tag- where is the service,what the contact of the service is and how do we communicate with the service


27) What are the advantages of hosting WCF in IIS?
  • Automation activation
  • Process Recycling
(When the browser disconnects the worker process stops and you loose all information. 
IIS also restarts theworker process. By default the worker process is recycled at around 120 minutes. So why does IIS recycle. By restarting the worker process it ensures any bad code or memory leak
do not cause issue to the whole system.)


 
 28) What is the difference between WCF and Web Service?

Web Service can be only invoke by HTTP.
WCF/Service can be invoked by any protocol and any transport type.


Web Services are not flexible.
WCF/ Services are flexible.(can add a new version by exposing a new end point so service are agile and very practicle)

29) What are different bindings supported by WCF?

You can use pre-defined bindngs and customer bindings in WCF.

 BasicHttpBinding:
  • Use SOAP over HTTP.
  • Can use HTTPS.
  • Can configure to send data in plain text or in optimized form like MTOM. 
WsHttpBinding:
  • Use SOAP over HTTP.
  • Same like BasicHttpBinding.
  • Supports Reliable message transfer( WS- ReliableMessaging),Security (WS-Security) and Transactions ( WS-AtomicTransaction)    

 NetTcpBinding:
  • Sends binary encoded SOAP.
  • Support Reliable message transfer, Security and Transactions directly over TCP.
  • Disadvantage : Client and Server should be made in .NET Language.
 NetNamedPipesBinding:
  • Sends binary encoded SOAP over named pipes.
  • Only usable for WCF- to- WCF communication between processes on the same Windows based machine. 
NetMsmqBinding:
  • Sends binary encode SOAP over MSMQ.
  • Can only be used for WCF-to-WCF communication.










No comments:

Post a Comment