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

Explain service contracts?

0 Answers  


We have already 2 hostings IIS and self hosting. there is another hosting ie WAS Hosting. What is the use of the WAS(Windows activation Service) compared to other hostings.

3 Answers   TCS,


What is the service?

0 Answers  


Difference between wcf and web services?

0 Answers  


What is the difference between wcf and wpf?

0 Answers  






WCF:What types of the operation contract parameters could be streamed?

3 Answers   Logica CMG,


do you know where we can host wcf services? : Wcf data services

0 Answers  


What are the Advantages of hosting wcf in iis?

0 Answers  


which is the best institute in hyderabad for advanced .net training and wcf.

8 Answers  


Explain the basic difference between WCF and ASMX Web Services?

0 Answers  


What is the elements of WCF service used in client side?

0 Answers  


do you know message contracts? : Wcf data services

0 Answers  


Categories