banner



How Do You Consume Wcf Service Codeproject

  • Download sample - twoscore.36 KB

Introduction

In this article, I will examine how to create and consume a WCF service. WCF is a next-generation programming platform and runtime organisation for building, configuring and deploying service-oriented applications. For more details, please come across here.

Creating a WCF Service

I will create a stock service to demonstrate a WCF service. To create a WCF service, please follow these steps:

  1. Launch Visual Studio 2008.
  2. Click on File -> new -> projection, and so select WCF service application.
  3. It volition create a WCF service awarding template.

I will delete the default contract and so create an IStock contract equally shown below.

Using the Code

          [          ServiceContract]          public          interface          IStock     {         [OperationContract]         Stock GetStock(string          Symbol);        }

The above contract has one method that returns a stock object for a given symbol. Hither is our Stock form that has Symbol, Engagement, Company and Close properties respectively.

          [          DataContract]          public          course          Stock     {         [DataMember]          public          string          Symbol {          become;          set; }         [DataMember]          public          DateTime Date {          become;          set; }         [DataMember]          public          string          Company {          get;          set; }         [DataMember]          public          decimal          Close {          get;          set; }     }

Next, I will delete the default service and create a Stock service that will implement the Istock contract as shown below:

          public          class          Stocks : IStock    {          #region IStock Members                    public          Stock GetStock(string          Symbol)        {            Stock st =          goose egg;          switch          (Symbol.ToUpper())            {          case          "          GOOG":                    st =          new          Stock { Symbol = Symbol, Date = DateTime.At present,            Company =          "          Google Inc.", Shut =          495          };          break;          instance          "          MSFT":                    st =          new          Stock { Symbol = Symbol, Date = DateTime.Now,            Visitor =          "          Microsoft Corporation", Close =          25          };          break;          case          "          YHOO":                    st =          new          Stock { Symbol = Symbol, Date = DateTime.Now,            Company =          "          Yahoo! Inc.", Shut =          17          };          break;          case          "          AMZN":                    st =          new          Stock { Symbol = Symbol, Date = DateTime.Now,            Company =          "          Amazon.com, Inc.", Shut =          92          };          break;            }          return          st;        }          

0 Response to "How Do You Consume Wcf Service Codeproject"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel