Click here to Skip to main content
15,886,199 members
Articles / Operations
Article

Service Contract in WCF

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Oct 2013CPOL1 min read 11.9K   1  
Service contract means the collective mechanisms by which a service’s capabilities and requirements are specified for its consumers. We must say that

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Service contract means the collective mechanisms by which a service’s capabilities and requirements are specified for its consumers. We must say that it define the operations that a service will perform when executed. It tells more thing about service like  message data types, operation locations, the protocols the client will need in order to communicate with the service. 
There are three types of attributes which are used to annotate these type of operations.
1. ServiceContractAttribute
2. OperationContractAttribute
3. MessageParameterAttribute.
 
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.
 
[ServiceContract(Name="MyService", Namespace="http://tempuri.org")]
 public interface IMyService
{

    [OperationContract]
    int AddNum(string numdesc, string assignedTo);
}
 
OperationContractAttribute: It can be applied only on methods. It is used to declare methods which belongs to Service Contract. It controls over the service description and message formats.

MessageParameterAttribute.: It controls how the names of any operation parameters and return values appear in the service description. It controls how both the parameter and return values are serialized to XML request and response elements at the transport layer. We need to use the  Name property because the variable name as it can’t be used as programming language.
 
[OperationContract]
    [return : MessageParameter(Name="reswait")]
    string MyOp([MessageParameter(Name="string")]string s);



 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
-- There are no messages in this forum --