1. How to define service contract in WCF?
Ans. Service Contract can be define using [ServiceContract] and [OperationContract] attribute.
2. Which attributes are similar to Servicecontract and Operationcontract in web services?
Ans. ServiceContract attribute is similar to the WebServcie attribute in the WebService
and OpeartionContract is similar to the WebMethod in WebService.
3. Can we create service without creating interface?
Ans. With out creating the interface, we can directly create the service by placing Contract in the implemented class.
But it is considered as bad practice of creating the service.
public class MyService
public int sum(int num1, int num2)
return num1 + num2;
4. What happens if we omit OperationContract attribute on any method in interface?
Ans. It will not be visible to client to consume.
5. What do you mean by Data Contract implicit or explicit in WCF?
Ans. Data contract can be explicit or implicit.
Simple types such as int, string etc has an implicit data contract.
User defined object are explicit or Complex type, for which you have to define a Data contract using [DataContract] and [DataMember] attribute.
6. Which assembly holds DataContract and DataMember?
Ans. System.Runtime.Serialization assembly holds the DataContract and DataMember attribute.
7. Which message format WCF will use for communication?
Ans. WCF uses SOAP(Simple Object Access Protocol) Message format for communication.
8. What is the format of SOAP message?
Ans. SOAP message contain Envelope, Header and Body.
SOAP envelope contains name, namespace,header and body element.
SOAP Hear contain important information which are not directly related to message.
SOAP body contains information which is used by the target.
9. What operational models does the WCF supports?
Ans. WCF supports either RPC(Remote Procedure Call) or Message style operation model.
10. If WCF automatically create the message for operation at run time the what is the use of MessageContract?
Ans.In Message style operation WCF allows to customize the message header and define the security for header and body of the message.
public class StudentDetails
public string StudID;
public string Name;
Here, we are passing StudID as a part of message header.