Buy Electronics

Wednesday, July 7, 2010

Basics of WCF

Overview of WCF

-> Windows Communication Foundation.
-> It combines functionalities of Asp.Net Web services, remoting, MSMQ and
Enterprise Services.

-> It’s more reliable and secured then Web services.
-> All the major changes can be done in the configuration file instead of code file.

********************************************************
Differences between WCF & Webservices

Hosting
---------
WCF can be hosted on IIS, WAS(Windows Activation Service), self-hosting.
WS can be hosted on IIS.

Attribute
----------
WCF has [ServiceContract] attribute attached with the class.
WS has [WebService] attribute attached with the class.
WCF has [OperationContract] attribute attached with methods.
WS has [WebMethod] attribute attached with methods.

WCF has [DataContract] attribute attached with the class.
WCF has [DataMember] attribute attached for a properties in the class,.

XML
-----
WCF uses System.Runtime.Serialization namespace for serialization.
WS uses System.Xml.Serialization namespace for serialization.


Transports
------------
WCF supports Http, Tcp, Msmq, P2P transport protocols.
Ex: The sample address for above transport schema may look like
http://localhost:81/MyService
net.tcp://localhost:82/MyService
net.pipe://localhost/MyPipeService
net.msmq://localhost/private/MyMsMqService

WS supports Http protocol.

Security
----------
WCF provides reliable security for messaging and transactions over net.
WS doesn’t provide method level security & message delivery isn’t assured & can be lost without acknowledgment.

There are three major Points in WCF

i)Address
WCF service location that client can use to expose its features

ii)Binding
Configuration for Transport protocol, security and encoding mechanism.

iii)Contract
It defines type of data and type of operations, a client application can use from WCF service.

***********************************************************
WCF configurations in config file :
-------------------------------------------
It declares information about endpoint name, address, binding and contract.

< system.serviceModel >
< client >
< endpoint name = "MyEndpoint"
address = "http://localhost:8000/MyService/"
binding = "wsHttpBinding"
contract = "IMyContract"
/>
</ client >
< / system.serviceModel >


Endpoint :
------------
In WCF the relationship between Address, Contract and Binding is called Endpoint.
The Endpoint is the fusion of Address, Contract and Binding.

Contracts :
-------------
In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does.

WCF defines four types of contracts.
1) Service contracts
Describe which operations the client can perform on the service.
There are two types of Service Contracts.
ServiceContract - This attribute is used to define the Interface.
OperationContract - This attribute is used to define the method inside Interface.

Ex:
[ServiceContract]
interface IMyContract
{
[OperationContract]
string MyMethod( );
}
class MyService : IMyContract
{
public string MyMethod( )
{
return "Hello World";
}
}

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

[DataContract]
class Contact
{
[DataMember]
public string FirstName;
[DataMember]
public string LastName;
}
If DataMember attributes are not specified for a properties in the class, that
property can't be passed to-from web service.

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


4 )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.







2 comments:

Raja | August 12, 2010 at 5:41 AM  

its nice

Raja | August 12, 2010 at 5:42 AM  

its useful to me.txs

Post a Comment

Tu comentario será moderado la primera vez que lo hagas al igual que si incluyes enlaces. A partir de ahi no ser necesario si usas los mismos datos y mantienes la cordura. No se publicarán insultos, difamaciones o faltas de respeto hacia los lectores y comentaristas de este blog.

Mobiles