What is DataContract and ServiceContract?Explain

Answers were Sorted based on User's Feedback



What is DataContract and ServiceContract?Explain..

Answer / vijay krishna

Data represented by creating DataContract which expose the
data which will be transefered /consumend from the serive
to its clients.

**Operations which is the functions provided by this
service.

To write an operation on WCF,you have to write it as an
interface,This interface contains the "Signature" of the
methods tagged by ServiceContract attribute,and all methods
signature will be impelemtned on this interface tagged with
OperationContract attribute.

and to implement these serivce contract you have to create
a class which implement the interface and the actual
implementation will be on that class.


Code Below show How to create a Service Contract:

[ServiceContract]
Public Interface IEmpOperations
{
[OperationContract]
Decimal Get EmpSal(int EmpId);

}

Class MyEmp: IEmpOperations
{
Decimal Get EmpSal()
{
// Implementation of this method.
}
}

Hope now you can differentiate between Data
Contract,Service Contract and OperationContract.

Is This Answer Correct ?    22 Yes 6 No

What is DataContract and ServiceContract?Explain..

Answer / pradeeprajasekharan

ServiceContract

Defines the Interface that is exposed through end points
which says what functionality will be available for the
client. So the ServiceContract attribute will be placed in
the interface level. Interface contains the definition of
the available methods through the service.

OperationalContract

Defines the methods under the service.


DataContract

Defines the mapping between CLR datatypes with XSD schema.
The complex datatypes will be serialized and deserialized
according to the DataContact attribute associated.

Is This Answer Correct ?    13 Yes 3 No

What is DataContract and ServiceContract?Explain..

Answer / sandeep

Service Contract:
Service contracts describe the operation that service can
provide. For Eg, a Service provide to know the temperature
of the city based on the zip code, this service is called as
Service contract. It will be created using Service and
Operational Contract attribute.

Data Contract:

Data contract describes the custom data type which is
exposed to the client. This defines the data types, that are
passed to and from service. Data types like int, string are
identified by the client because it is already mention in
XML schema definition language document, but custom created
class or data types cannot be identified by the client e.g.
Employee data type. By using DataContract we can make client
to be aware of Employee data type that are returning or
passing parameter to the method.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More WCF Interview Questions

What is wcf full form?

0 Answers  


Explain Address, Binding, and contract for a WCF Service?

0 Answers  


What is "per call" instance mode in wcf?

0 Answers  


How can you generate proxies using svcutil in wcf?

0 Answers  


Explain about contracts?

0 Answers  






What is mean by wcf?

0 Answers  


Is MSMQ works in two-way communications in WCF?

0 Answers   Viscus Infotech,


Explain how does WCF works?

0 Answers  


do you know what is endpoint in wcf? : Wcf data services

0 Answers  


What is difference between wpf and wcf?

0 Answers  


How many types of contracts in WCF?

0 Answers  


what are the MEPs available in WCF?

0 Answers  


Categories