Click here to Skip to main content
15,894,180 members
Articles / Programming Languages / C#

Creating and Consuming Your First WCF Service

Rate me:
Please Sign up or sign in to vote.
4.21/5 (57 votes)
25 Sep 2009CPOL2 min read 658.9K   18.3K   88  
In this article, I will examine how to create and consume a WCF service. WCF is next-generation programming platform and runtime system for building, configuring and deploying service-oriented applications.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfSample
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
    public class Stocks : IStock
    {
        #region IStock Members

        public Stock GetStock(string Symbol)
        {
            Stock st = null;
            switch (Symbol.ToUpper())
            { 
                case "GOOG":
                    st = new Stock { Symbol = Symbol, Date = DateTime.Now, Company = "Google Inc.", Close = 495 };
                    break;
                case "MSFT":
                    st = new Stock { Symbol = Symbol, Date = DateTime.Now, Company = "Microsoft Corporation", Close = 25 };
                    break;
                case "YHOO":
                    st = new Stock { Symbol = Symbol, Date = DateTime.Now, Company = "Yahoo! Inc.", Close = 17 };
                    break;
                case "AMZN":
                    st = new Stock { Symbol = Symbol, Date = DateTime.Now, Company = "Amazon.com, Inc.", Close = 92 };
                    break; 
            }

            return st;
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) http://www.Fairnet.com
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions