Click here to Skip to main content
Click here to Skip to main content
Go to top

Service Orientation and WCF

, 16 Aug 2006
Rate this:
Please Sign up or sign in to vote.
An article about service orientation in Windows communication foundation
<!---------------------------------------------------------------------------><!-- INTRODUCTION The Code Project article submission template (HTML version) Using this template will help us post your article sooner. To use, just follow the 3 easy steps below: 1. Fill in the article description details 2. Add links to your images and downloads 3. Include the main article text That's all there is to it! All formatting will be done by our submission scripts and style sheets. --><!---------------------------------------------------------------------------><!---------------------------------------------------------------------------><!------------------------------- STEP 1 --------------------------->
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
<!------------------------------- STEP 2 ---------------------------><!-- Include download and sample image information. --><!------------------------------- STEP 3 ---------------------------><!-- Add the article text. Please use simple formatting (

,

etc) -->

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

Smile | :) I am done with the first version. <!------------------------------- That's it! ---------------------------></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

Share

About the Author

Bibin.Mohan
Web Developer
United States United States
Presently working with US Technology Resources, Trivandrum.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.141002.1 | Last Updated 17 Aug 2006
Article Copyright 2006 by Bibin.Mohan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid