blogspot visit counter

Friday, 16 May 2014

Wcf interview questions and answers for experienced

Wcf interview questions and answers for experienced
Categories :-MVC interview questions and answers , Latest interview questions and answers for experienced , ADO.Net Interview Questions and Answers  .

 What is WCF?

Ans.  WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types.WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it

. Difference between WCF and Web Services?

A. Below are the main differences between the WCF and Web Service:
Web Service:
a.    Can be hosted in IIS only
b.    Only two types of operations affects- One-Way, Request-Response
c.     To serialize the data use System.Xml.Serialization
d.    To encode the data use- XML 1.0, MTOM, DIME, Custom
WCF service:
a.    Can be hosted in IIS, Self Hosting, WAS, Windows Services etc
b.    Three types of operations affects- One-Way, Request-Response and Duplex
c.     To serialize the data use System.Runtimel.Serialization
d.    To encode the data use- XML 1.0, MTOM,Binary, Custom
e.    WCF Service can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P etc.

 What are Endpoints?

Ans. The collection of Address, Binding and Contract is called as End Point. In Sort,
EndPoint = A+B+C
Address (Where)-  it means where the service is hosted. URL of the service shows the address.
Binding (How)- How to connect to the service, is defined by the Binding. It basically has the definition of the communication channel to communicate to the WCF service
Contract (what)- It means what the service contains for the client. What all the methods are implemented in the WCF service is implemented in the Contract.

 What are Behavior and Bindings?

Ans. Binding mainly describes about the communication of the client and service. For this, there are protocols corresponding to the binding behavior which will take care of the communication channel. There are different protocols which we use for the different types of bindings. E.g. HTTP, TCP, MSMQ, Named Pipes etc.
Behavior is used for the common configurations that could be for endpoints. When we use the common behavior, they affect to all the end points. Adding the service behavior affect the service related stuff while the endpoint related behavior affects the end points. Also operations level behavior affects the operations.

 What are different types of Contracts supported?

Ans. There are mainly 5 type of contracts used in WCF service:
a. Service Contract
b. Operation Contract
c. Data Contract
d. Message Contract
e. Fault Contract

 What is the difference between Transport and Message Security mode?

Ans. WCF supports 2 types of security- Transport Level Security and Message Level Security
Transport Level Security- In this type of security, we make the transport channel as secure so that the data flows in that channel will be automatically secured. For HTTP channel, we use the client certificate for the security of the web address. SSL is used for the HTTP channel security. As we don’t need to secure each of the messages which are floating between the client and the service, the speed is faster as direct message is going to the client from the service.
Message level security- This type of security in WCF is used where we don’t have the fixed transport medium and we need to secure each message which is floating between the server and the client. In this type of security we use certain algorithms for making the message as secure message. We use some extra bits and send with the message. We also use some encryption techniques like SHA1 or MD5 which make the proper security for our message. As each message needs to be secured, this type of security makes some delay in the process of sending and receiving the messages.

. How to configure WCF security to support Windows authentication?

Ans. To support the WCF security in Windows Authentication, we need to add the ClientCredetialType attribute to “Windows” under the security tab element:
transport clientCredentialType="Windows"

 How to use Fault Contract?

Ans.  Fault Contract is mainly used for viewing and displaying the errors which occurred in the service. So it basically documents the error and the error message can be shown to the user in the understandable way. We can’t use here the try….catch block for the error handling because the try…catch is the technology specific (.Net Technology). So we use the Fault contract for the error handling.
e.g. To use the Fault contract, we can simply write like the below:
public  int Add(int number1,int number2)
  // write some implementation
 throw new FaultException (“Error while adding data..”);
Here the fault Exception method is the inbuilt method which will throw the exception and display the message . We can use the custom class so that the message can be customized and the customized message can be sent to the client.
So we can creeat  a clss like:
Public Class CustomException()
public int ID{get;set;}
public string Message{get;set;}

public string Type{get;set;}
Now this custom type we ca use with the Operation Contract as:
Public interface IMyInterface
Int Add(int num1,int num2);
Now while implementation of the Add method, we can assign the class properties.

1 comment:

Related Posts Plugin for WordPress, Blogger...