WCF Azure Silverlight Calculator

This sample creates a simple WCF calculator service and builds a Silverlight client for it. The client is then hosted alonside the service in the Azure fabric.

 
 
 
 
 
4 Star
(4)
5,454 times
Add to favorites
4/27/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
VB.NET
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;

namespace SilverlightService
{
    [ServiceContract]
    public class Service
    {
        [OperationContract]
        public int Calculate(Operation op, int a, int b)
        {

            Trace.Listeners["AzureDiagnostics"].WriteLine("Performing operation: " + op);

            switch (op)
            {
                case Operation.Add:
                    return a + b;
                    break;

                case Operation.Subtract:
                    return a - b;
                    break;

                case Operation.Multiply:
                    return a * b;
                    break;

                case Operation.Divide:
                    return a / b;
                    break;
            }

            return 0;
        }
    }

    public enum Operation
    {
        Add,
        Subtract,
        Multiply,
        Divide
    }
}