Sunteți pe pagina 1din 16

BRICS

WCF Part 1
Vijendra Kushwaha

What is WCF?

BRICS

WCF stands
for Windows Communication Foundation. It is Microsoft's
?
latest technology that enables applications in a distributed environment to
communicate with each other.WCF is Microsoft's unified programming
model for building service-oriented applications. It enables developers to
build secure, reliable, transacted solutions that integrate across platforms
and interoperate with existing.
WCF is an umbrella technology that covers ASMX web services, .NET
remoting, WSE and System.Messaging. It is designed to offer a
manageable approach to distributed computing, broad interoperability,
and direct support for service orientation. WCF supports many styles of
distributed application development by providing a layered architecture.

WCF Features
Service Orientation
Interoperability
Multiple Message Patterns
Multiple Transports and Encodings
Reliable and Queued Messages
Transactions
AJAX and REST Support
Extensibility
Service Metadata
Security

BRICS

Difference : WCF & WebService

BRICS

WCF

WebService

Supports various protocols like HTTP,


HTTPS, TCP, Named Pipes and MSMQ.

Supports only HTTP, HTTPS protocols.

Hosted in IIS, WAS (Windows


Activation Service), Self-hosting,
Windows Service.

Hosted only in IIS.

Supports security, reliable messaging,


transaction and AJAX and REST
supports.

Support security but is less secure as


compared to WCF.

Supports One-Way, Request-Response


and Duplex service operations.

Supports One-Way and RequestResponse service operations.

Supports XML,MTOM, Binary message


encoding.

Supports XML and MTOM (Message


Transmission Optimization Mechanism)
message encoding.

Unhandled Exceptions does not return


to the client as SOAP faults. WCF
supports better exception handling by
using FaultContract.

Unhandled Exceptions returns to the


client as SOAP faults.

Supports multi-threading by using


ServiceBehaviour class.

Doesnt support multi-threading.

BRICS

EndPoint : Address, Binding and contract

All communication with a Windows Communication Foundation (WCF)


service occurs through the endpoints of the service. Endpoints provide
clients access to the functionality offered by a WCF service.
Each endpoint consists of four properties:
An address that indicates where the endpoint can be found.
A binding that specifies how a client can communicate with the endpoint.
A contract that identifies the operations available.
A set of behaviors that specify local implementation details of the
endpoint.

BRICS

EndPoint : Address, Binding and contract

Address: The address uniquely identifies the endpoint and tells potential
consumers of the service where it is located. It is represented in the WCF
object model by the EndpointAddress class. An EndpointAddress class
contains a Uri property, which represents the address of the service.
Binding: The binding specifies how to communicate with the endpoint.
This includes:
The transport protocol to use (for example, TCP or HTTP).
The encoding to use for the messages (for example, text or binary).
The necessary security requirements (for example, SSL or SOAP
message security).

BRICS

EndPoint : Address, Binding and contract

Contracts: The contract outlines what functionality the endpoint exposes


to the client. A contract specifies:
What operations can be called by a client.
The form of the message.
The type of input parameters or data required to call the operation.
What type of processing or response message the client can expect.
Behaviors:
You can use endpoint behaviors to customize the local behavior of the
service endpoint. Endpoint behaviors achieve this by participating in the
process of building a WCF runtime.

Bindings

BRICS

Basic binding
This binding is provided by the BasicHttpBinding class. It is designed to
expose a WCF service as an ASMX web service, so that old clients (which
are still using ASMX web service) can consume new service. By default, it
uses Http protocol for transport and encodes the message in UTF - 8 text
format. You can also use Https with this binding.
Web binding
This binding is provided by the WebHttpBinding class. It is designed to
expose WCF services as Http requests by using HTTP-GET, HTTP-POST. It
is used with REST based services which may give output as an XML or
JSON format
WS Http binding
This binding is provided by the WSHttpBinding class. It is like as Basic
binding and uses Http or Https protocols for transport. But this is
designed to offer various WS - * specifications such as WS Reliable
Messaging, WS - Transactions, WS - Security and so on which are not
supported by Basic binding.
wsHttpBinding= basicHttpBinding + WS-* specification

Bindings

BRICS

WS Dual binding
This binding is provided by the WsDualHttpBinding class. It is like as
wsHttpBinding except it sup-ports bi-directional communication means
both clients and services can send and receive messages.
TCP binding
This binding is provided by the NetTcpBinding class. It uses TCP protocol
for communication between two machines with in intranet (means same
network). It encodes the message in binary format. This is faster and
more reliable binding as compared to the Http protocol bindings. It is only
used when communication is WCF - to WCF means both client and
service should have WCF.
IPC binding
This binding is provided by the NetNamedPipeBinding class. It uses
named pipe for Communication between two services on the same
machine. This is the most secure and fastest binding among all the
bindings.

Bindings

BRICS

MSMQ binding
This binding is provided by the NetMsmqBinding class. It uses MSMQ for
transport and offers support to disconnected message queued. It provides
solutions for disconnected scenarios in which service processes the
message at a different time than the client send the messages.

Contracts

BRICS

Service Contract
Service contract describes the operations, or methods, that are available
on the service endpoint, and exposed to the outside world. A Service
contract describes the client-callable operations (functions) exposed by
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.
[ServiceContract]
interface ISaleService
{
[OperationContract]
bool InsertCustomer(Customer obj);
}

Contracts

BRICS

Data Contract
In one line, data contract describes the data to be exchanged. To define a
data contract, you simply decorate a class or enumeration with
[DataContract] attribute, as shown below.
[DataContract]
public class Customer
{
[DataMember]
public int CustomerID;
[DataMember]
public string CustomerName;
[DataMember]
public string Address;
[DataMember]
public string EmailId;
}

Contracts

BRICS

Message Contract
A Message Contract is used to control the structure of a message body
and serialization process. It is also used to send / access information in
SOAP headers.
[MessageContract]
public class EmployeeDetails
{
[MessageHeader]
public string EmpID;
[MessageBodyMember]
public string Name;
[MessageBodyMember]
public string Designation;
[MessageBodyMember]
public int Salary;
[MessageBodyMember]
public string Location;
}

WCF Hosting

BRICS

WCF comes with the possibility of being invoked and used by protocols
other than HTTP. So along with IIS, WCF can also be hosted in different
ways so that its full power can be utilized(if required).
A WCF service can be hosted in following ways:

Hosting
Hosting
Hosting
Hosting

in
in
in
in

Internet Information Services(IIS).


Windows Activation Services(WAS).
a Console or Desktop application(Self hosting).
a Windows Service.

WCF Architecture

BRICS

BRICS

Demo Application

S-ar putea să vă placă și