Franc Stratton's .NET (TM) Web Application, OOP, and SOA Architecture & Programming Site

A site devoted to ASP.NET (TM), SilverLight (TM) and Browser-Based WPF (TM) Applications, IIS Services, and OOP Architectures

Home     Architecture Overview     WF/WCF/WPF     Data Store     Standards     .NET Security     Resources     jQuery     Silverlight     Developer Tips     Blog     Site Map      
WF
WPF
WCF
WCF Details
Windows Communication Foundation (WCF)
 
Windows Communication Foundation, or WCF, allows the development of connected applications through a service-oriented architecture programming model with a layered architecture. At its basic level, the WCF channel architecture provides asynchronous, untyped message-passing primitives, but built on top of this base are protocol facilities for secure, reliable, transacted data exchange and broad choice of transport and encoding options that include the top two: HTTP for SOAP messaging thorugh firewalls and the Internet; and TCP for fast Intranet connections. Other transport protocols are available as well.

The WCF typed programming model (called the service model) allows the development of distributed applications and provides developers that have expertise in ASP.NET Web services, .NET Framework remoting, and Enterprise Services, and who are coming to WCF with a familiar development experience in the Visual Studio 2008 IDE the tools to provide secure and reliable services.  The service model features a straightforward mapping of Web services concepts to those of the .NET Framework common language runtime (CLR), including flexible and extensible mapping of messages to service implementations in languages such as Visual C# or Visual Basic. It includes serialization facilities that enable loose
coupling and versioning, and it provides integration and interoperability with existing .NET Framework distributed systems technologies such as Message Queuing (MSMQ), COM+, ASP.NET Web services, Web Services Enhancements (WSE), and a number of other functions.


This service development paradigm introduces a new development environment for distributed applications since it is designed to interoperate well with the non-WCF applications as well. There are two important aspects to WCF interoperability: interoperability with other platforms, and interoperability with the Microsoft technologies that preceded WCF. An application built on WCF can interact with all of the following:

1. WCF-based applications running in a different process on the same Windows machine.

2. WCF-based applications running on another Windows machine.

3. Applications built on other technologies, such as J2EE application servers, that support standard Web services. These applications can be running on Windows machines or on machines running other operating systems like Lennix or Unix.

Steps to Create a WCF Service

 

Server side needs of WCF

 

1. Service contract: defines operations exposed at the service boundary and data passed that is passed through these operations.

 

2. Service data contracts: needed for defining complex types passed through service contract operations.

 

3. Service implementation: provides functional code to process incoming service information to determine what to do with it.

 

4. Service configuration: specifies how service is exposed in terms of address, binding, and contract (ABCs of WCF) which includes network protocol, message encoding, security methodologies, reliability, transactions, etc.

 

5. Service host: determines the process on which the service runs such as self-hosting, IIS or Windows Activation Service (WAS).

 

6. Service behavior: enables the service for metadata exchange (thereby allowing users to browse its wsdl), the programmer will need to set the metadata exchange properties for the service. Behavior is a collection of attributes that can be set and applied to the service.

 

7. Service instancing: determines the mode of operation for the service object (Per-call, per-session, or singleton).

 

PerCall: A new InstanceContext (and therefore service object) is created for each client request.

PerSession: A new InstanceContext (and therefore service object) is created for each new client session and maintained for the lifetime of that session (this requires a binding that supports sessions).

Single: A single InstanceContext (and therefore service object) handles all client requests for the lifetime of the application.

 

Steps to Create a WCF Service (Continued)

 

Client side needs of WCF

 

1. Service contract definition: matches the server side WCF contract.

 

2. Service data contract definition: matches the server side WCF data contract.

 

3. Service proxy: forms the messages to send to the WCF service and processes the returned messages.

 

Use WCF Service Best Practices

 

1. Build a service layer: This implies that service definitions in its own separate class library and host library in the service host environment.

 

2. Layer the service: The services layer makes calls to the Business Logic Layer (BLL) which makes calls to the Data Access Layer (DAL) for database access.

 

3. Provide for Interoperability: When exchanging information, do not pass .NET-specific types such as ADO datasets or exceptions. Instead, pass simple data structure objects instantiated from classes with public properties and private members.

 

4. Use per call-instancing: WCF now defaults on per-session instancing which allows the client to keep a service instance alive until as long as client keeps making calls for a non-recommended stateful conversation. The singleton mode is just as bad for scalability problems.

 

5. Deal with exceptions: The service should catch all exceptions and throw a FaultException exception

 

6. Choose an Appropriate service host.