Click here to Skip to main content
15,860,972 members
Articles / Operating Systems / Windows
Article

Service Orientation and WCF

Rate me:
Please Sign up or sign in to vote.
2.10/5 (11 votes)
16 Aug 20062 min read 22.7K   6  
An article about service orientation in Windows communication foundation
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
{
    // This is the functional specification contract
    [ServiceContract()]
    public interface IBasicService
    {
        [OperationContract(IsOneWay = false)]
        string GreetUser(string strUsername);
    }

    // And this is the functional specification implementation
    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);

            // Add "plugin" to speak to SOAP clients
            BasicHttpBinding bhb = new BasicHttpBinding(BasicHttpSecurityMode.None);
            host.AddServiceEndpoint(typeof(IBasicService), bhb, "WCF_BasicService_SOAP");


            // Add "plugin" to speak to TCP clients
            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>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Presently working with US Technology Resources, Trivandrum.

Comments and Discussions

 
-- There are no messages in this forum --