Title: Service Orientation and WCF
Author: Bibin Isac Mohan
Email: Bibin.mohan@yahoo.com
Environment: WinFx
Keywords: WCF
Level: Beginner"
Description: An article about service orientation in Windows communication foundation
Section Miscellaneous
SubSection General
Introduction
WCF is based on the principles of service orientation through message exchanges. Services are functionalities provided to the consumers. Here basically we provide services, rather than Methods or Classes. Service orientation is a way of thinking, not a way of implementation, not dependent on any platform. Services are built to last, thr availability and stability are critical.
Background
Service orientation is based on its 4 fundamental tenets.
- Boundaries are explicit – A boundary represents the border between a service’s public interface and its internal public implementation. In case of ASP.net web service, a services boundary is published through WSDL. Services are defined in a way that its internal implementation details are not exposed through any interface. Each service interaction deals with boundary crossing. Because each
- cross-boundary communication is potentially costly, service-orientation is based on a model of explicit message passing rather than implicit method invocation.
- Services are autonomous - Individual services are always deployed, versioned, and managed independently. To maintain system integrity, service-oriented designs use techniques such as transactions, durable queues, redundant deployment and failover.
- Services share schema and contract, not class - Services interact based solely on schemas (for structures) and contracts (for behaviors). This strict separation between structure and behavior vastly simplifies deployment. Unlike object oriented classes, services do not conflate structure and behavior.
- Service compatibility is determined based on policy - The WS-Policy specification defines a machine-readable policy framework capable of expressing service-level policies, enabling them to be discovered or enforced at execution time. Policy expressions indicate which conditions and guarantees (called assertions) must hold true to enable the normal operation of the service.
Services are mainly about reducing shared assumptions and hence increased flexibility. Object Orientation is mainly about ease of use, transparency, lots of assumptions and less flexible.
Programming service in WCF
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
namespace WCF_BasicService
{
[ServiceContract()]
public interface IBasicService
{
[OperationContract(IsOneWay = false)]
string GreetUser(string strUsername);
}
internal class BasicService : IBasicService
{
public string GreetUser(string strUsername)
{
return "Hello " + strUsername;
}
}
class Program
{
static void Main(string[] args)
{
Uri urlService = new Uri("http://localhost:1979/2006");
ServiceHost host = new ServiceHost(typeof(BasicService), urlService);
BasicHttpBinding bhb = new BasicHttpBinding(BasicHttpSecurityMode.None);
host.AddServiceEndpoint(typeof(IBasicService), bhb, "WCF_BasicService_SOAP");
NetTcpBinding tcp = new NetTcpBinding(System.ServiceModel.Channels.SecurityMode.None);
host.AddServiceEndpoint(typeof(IBasicService),
tcp,
"net.tcp://localhost/2006/WCF_BasicService_TCP");
host.Open();
Console.WriteLine("WCF_BasicService is running. Press ENTER to shutdown.");
Console.ReadLine();
host.Close();
host.Dispose();
}
}
}
History
:-) I am done with the first version. </body> </html>