Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

WCF Features

Windows Communication Foundation (WCF) is unified programming model introduced in .Net Framework 3.0. WCF is a combined feature of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication.

WCF Features:


Extensible:

With behaviors we can add custom changes; Small changes in the configuration will make your requirements. If extra capability is required, there are a number of entry points that allow you to customize the behavior of a service.

Reliable and Secure:

With WCF you can encrypt messages, you can provide user authentication.
Security can also be implemented using well-known standards such as SSL or WS-SecureConversation.
WCF supports reliable message exchange using reliable sessions implemented over WS-Reliable Messaging and using MSMQ.

Security Authentication Example:

<wsHttpBinding>
        <binding name="WSHttpBinding_ILeaveSummeryWebService" receiveTimeout="02:50:00"
          maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <securitymode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" algorithmSuite="xyztestName256" />
          </security>
        </binding>
</wsHttpBinding>


Transactions:

WCF supports transactions, it uses below three models for transactions:
1.  WS-AtomicTtransactions 
2.  System.Transactions namespace
3.  Microsoft Distributed Transaction Coordinator

Service Orientation:

WCF provides great feature to build loosely coupled application called service oriented application. The services have the general advantage of being loosely-coupled instead of hard-coded from one application to another.

Exception Handling:

Exception handling in WCF is performed with following :

a.  Using fault contracts
b.  Directly handling the exception thrown.
c.  Implementing the IErrorHandler interface
d.  Handling ServiceHost events

Durable, Reliable and Queued Messages:

WCF ensures durable message communication, it uses database to save messages with durable message pattern if any disruption occurs messages are saved in database.

Service Metadata:

WCF supports publishing service metadata using best industry standards such as WSDL, XML Schema and WS-Policy.

Interoperability:

WCF implements modern industry standards for Web service interoperability.

Multiple Message Patterns :

Messages are exchanged in one of several patterns. The most common pattern is the request/reply pattern, where one endpoint requests data from a second endpoint.

REST Web service and AJAX support:

Presently WCF supports REST web services and also AJAX. WCF can be configured to process "plain" XML data that is not wrapped in a SOAP envelope.
 

WCF Endpoints

Each end point is medium to communicate with external world. All communication with WCF service occurs through the endpoints of the service.

Each END point consist four properties:

1.  Address (Where)   2.  Binding (How)   3. Contract (What)   4. Behavior (Custom Changes)

Address:

Simply tells external world where service located. The URL specifies where this WCF service is hosted .Client will use this URL to connect to the service.
Example: http://localhost/EmployeeLeavesService/LeaveSummery.svc

Binding:

Binding explains how client communicate with WCF service. There are different protocols used in binding, you can use any protocol according to your WCF service requirement.

Protocols:

BasicHttpBinding:       

Classic(Basic before WCF) web service,No security by default

WSHttpBinding:                  

With WS-* support. Supports Security,transactions

WSDualHttpBinding:   

With duplex contract and transaction support

WSFederationHttpBinding:

With federated security. Supports transactions

MsmqIntegrationBinding:

Communication directly with MSMQ applications. Supports transactions

NetMsmqBinding:      

Communication between WCF applications by using queuing. Supports transactions

NetNamedPipeBinding:       

Communication between WCF applications on same computer. Supports duplex contracts and transactions

NetPeerTcpBinding: 

Communication between computers across peer-to-peer services. Supports duplex contracts

NetTcpBinding:         

Communication between WCF applications across computers. Supports duplex contracts and transactions

Binding Example:

Basic HTTP:

<basicHttpBinding>
  <binding name="BasicHttpBinding_ILeaveSummeryWebService" receiveTimeout="02:50:00" maxReceivedMessageSize="2147483647" />
 </basicHttpBinding>

 

WS HTTP:

 

<wsHttpBinding>
        <binding name="WSHttpBinding_ILeaveSummeryWebService" receiveTimeout="02:50:00"
          maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" algorithmSuite="xyztestName256" />
          </security>
        </binding>
</wsHttpBinding>


Contract:

A contract that specifies what operations available, operations specifies what endpoint will communicate with external world.
<endpoint contract="ILeaveSummeryWebService" binding="wsHttpBinding" bindingConfiguration="WsHttpBinding_ILeaveSummeryWebService" address="http://localhost/EmployeeLeavesService/LeaveSummery.svc" />

Behavior:

A set of behaviors that specify local implementation details of the endpoint.

<serviceBehaviors>
        <behavior name=" EmployeeLeavesWebServiceBehaviour">
          <!--Set this to a high value in order to be able to serialize many objects--> 
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
 
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="false" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug httpHelpPageEnabled="false" includeExceptionDetailInFaults="true" />
            <serviceCredentials>
                <userNameAuthentication userNamePasswordValidationMode="Custom"
                                        customUserNamePasswordValidatorType="EmployeeLeavesService.LeaveCustomUserNameValidator, EmployeeLeavesService" />
            </serviceCredentials>
 
        </behavior>
      </serviceBehaviors>
    </behaviors>
 
 

Windows Communication Foundation (WCF)

Definition:
Windows Communication Foundation (WCF) is a framework in Microsoft .Net for building connected, service-oriented applications.

Description:

Using WCF web service, you can send data as asynchronous messages from one service endpoint to another.  It is unified programming model introduced in .Net Framework 3.0. WCF is a combined feature of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication.


ABC of WCF (Address, Binding, Contract):

Address: where this WCF service is hosted .Client will use this URL to connect to the service.
Binding: how client communicate with WCF service.
Contract: what operations available in WCF service.  

Some advantages using WCF service over Classic ASMX web services:

a. WCF services provide better reliability and security in compared to ASMX web services.
b. Provides transaction feature.
c. Small changes in the configuration will meet your requirements.
d. Support hosting in IIS,WAS(Windows activation service),Self hosting, Windows Service.
e. Support different types of bindings((TCP/IP, HTTP,HTTPS , PIPE, MSMQ etc.).
f. Better Exception handling.
g . Supports multi-threading by using ServiceBehaviour class.
h. Improved performance compared to ASMX web services.