Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> WCF >> WCF contracts.
WCF contracts.

In this blog I will give you an introductory knowledge in WCF contracts.
Views: 1691     Comments: 1
by James Smith on 8/1/2011

Contracts in WCF

In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does. In this blog I will told you that which type of contracts available in WCF and how we can use them. This blog is only provides an introductory knowledge in WCF contracts.

WCF defines four types of contracts.

Service contracts

Service contracts define which type of operations the client can perform on the service. We used two types of attributes to define service contract.

ServiceContract - This attribute is used to define the Interface.

OperationContract - This attribute is used to define the method inside Interface.

Example of service contracts

[ServiceContract]

interface IServiceContract

{

   [OperationContract]

   string MyMethod( );

}

class Service : IServiceContract

{

   public string HelloWorld( )

   {

      return "Hello World";

   }

}

Data contracts

Data contracts define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.

There are two types of Data Contracts.

DataContract –DataContract  attribute used to define the class

DataMember –DataMember  attribute used to define the properties.

Example of Data contracts

[DataContract]

class ServiceContract

{

   [DataMember]

   public string Name;

   [DataMember]

   public string City;

}

If DataMember attributes are not specified for a properties in the class that property can't be passed to-from web service.

Fault contracts

Define which errors are raised by the service, and how the service handles and propagates errors to its clients.

Message contracts

Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.


WCF contracts
by Awadhendra Tiwari on 2/3/2012
Good one. Keep writing.
Report Abuse
Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by James SmithRSS Feed
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 6026
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.