in Education by

What is Service Contract in WCF?

1 Answer

0 votes
by

Service contract means the collective mechanisms by which a service's capabilities and requirements are specified for its consumers. We must say that it defines the operations that a service will perform when executed. It tells more things about a service, like message data types, operation locations, the protocols the client will need in order to communicate with the service.

To create a service contract you define an interface with related methods representative of a collection of service operations, and then decorate the interface/class with the ServiceContract Attribute to indicate it is a service contract. Methods in the interface that should be included in the service contract are decorated with the OperationContract Attribute.

How to define a Service Contract

Service Contract


ServiceContractAttribute: It is used to declare the type as a Service Contract. It can be declared without any parameters but it can also take named parameters.

  1. [ServiceContract(Name="MyService", Namespace="http://tempuri.org")]  
  2. public interface IMyService  
  3. {  
  4.    [OperationContract]  
  5.    int AddNum(string numdesc, string assignedTo);  
  6. }  

OperationContractAttribute: It can only be applied on methods. It is used to declare methods which belong to a Service Contract. It controls the service description and message formats.

Related questions

0 votes
    Why Should We Use WCF Service?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    What is the difference between WCF and Web services?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    What are the features and advantage of WCF?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    Using the WCF web programming model one can specify an operation contract like so: [OperationContract] [WebGet ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    What is Fault Contract in WCF?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    What is Message Contract in WCF?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
0 votes
    A formal contract between a Service Provider (SP) and a Service Consumer (SC) is known as a. Service Level ... d. Cloud Economic Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    A formal contract between a Service Provider (SP) and a Service Consumer (SC) is known as what? Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    What is Boxing and Unboxing in C#?...
asked Jul 9, 2021 in General by JackTerrance
0 votes
    What is the Tab Control in WPF?...
asked Apr 9, 2021 in Education by JackTerrance
...