Social Networks

Introduction:
WCF simplifies the development effort to make service oriented applications by combining the technologies together, leading to higher development productivity. Also, it reduces the complexity of applications by unifying Enterprise Services, Messaging, .NET Remoting, Web Services, and WSE. WCF builds applications with an attributed programming model, leading to higher developer productivity.
WCF_All

WCF Communication Model

Windows Communication Foundation (WCF) follows a client–server model to establish communication between applications. Client applications can directly access services through Endpoints exposed by the service. Endpoints are nothing but locations defined, through which messages can be sent or received, and a service can have multiple endpoints.
WCF_Services

A WCF Service is comprised of the following major components. The diagram below shows how the components are related to each other:

  • Service Contract
  • Operation Contract
  • Data Contract
  • Data Member

WCF_Services_contract

Service Contract

Service contract is a contract that specifies the direction and type of the messages in a conversation. It is an interface or a class that defines the service contract in a Windows Communication Foundation (WCF) application. A service contract is the gateway to a service for external applications to make use of the service functions, and at least one service contract should be available in a service.

[ServiceContract]

interface IMyContract

{

[OperationContract]

string MyMethod( );

}

class MyService : IMyContract

{

public string MyMethod( )

{

return “Hello World”;

}

}

Operation Contract

An operation contract defines the methods of the service that are accessible by external systems. TheOperationContract attribute needs to be applied for all these methods, these are also like web methods in a web service.

Data Contract

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 – attribute used to define the class
DataMember – attribute used to define the properties.

[DataContract]

class Contact

{

   [DataMember]

   public string FirstName;

   [DataMember]

   public string LastName;

}

 

Data Member

A data member specifies the type which is part of a data contract used as a composite type member of the contract. To define a data member, apply the DataMember attribute to the fields that must be serialized. The DataMemberattribute can be applied to private properties, but they will be serialized and deserialized, and will be accessible to the user or process.

[DataContract]
public class StudentInformation
{
_studentId = studId;

[DataMember]
public int StudentId
{
get { return _studentId; }
set { _studentId = value; }
}

}

WCF Architecture

None found.

Leave a Reply

Your email address will not be published. Required fields are marked *

Allowed Tags:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>