Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 3.19 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Trouble following Microsoft's WCF tutorial
  2. svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service
  3.        
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Description;
  10.  
  11. namespace Microsoft.ServiceModel.Samples
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             Uri BaseAddress = new Uri("http://locoalhost:8000/ServiceModelSamples/Service");
  18.             ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), BaseAddress);
  19.  
  20.             try
  21.             {
  22.                 selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");
  23.                 ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
  24.                 smb.HttpGetEnabled = true;
  25.                 selfHost.Description.Behaviors.Add(smb);
  26.  
  27.                 selfHost.Open();
  28.                 Console.WriteLine("The service is ready.");
  29.                 Console.WriteLine("Press <ENTER> to terminate service.");
  30.                 Console.WriteLine();
  31.                 Console.ReadLine();
  32.                 selfHost.Close();
  33.             }
  34.             catch (CommunicationException ce)
  35.             {
  36.                 Console.WriteLine("An expection occurred: {0}", ce.Message);
  37.                 selfHost.Abort();
  38.             }
  39.         }
  40.  
  41.         [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
  42.         public interface ICalculator
  43.         {
  44.             [OperationContract]
  45.             double Add(double n1, double n2);
  46.  
  47.             [OperationContract]
  48.             double Subtract(double n1, double n2);
  49.  
  50.             [OperationContract]
  51.             double Multiply(double n1, double n2);
  52.  
  53.             [OperationContract]
  54.             double Divide(double n1, double n2);
  55.         }
  56.  
  57.         public class CalculatorService : ICalculator
  58.         {
  59.             public double Add(double n1, double n2)
  60.             {
  61.                 double result = n1 + n2;
  62.                 Console.WriteLine("Received Add({0},{1})", n1, n2);
  63.                 // Code added to write output to the console window.
  64.                 Console.WriteLine("Return: {0}", result);
  65.                 return result;
  66.             }
  67.  
  68.             public double Subtract(double n1, double n2)
  69.             {
  70.                 double result = n1 - n2;
  71.                 Console.WriteLine("Received Subtract({0},{1})", n1, n2);
  72.                 Console.WriteLine("Return: {0}", result);
  73.                 return result;
  74.             }
  75.  
  76.             public double Multiply(double n1, double n2)
  77.             {
  78.                 double result = n1 * n2;
  79.                 Console.WriteLine("Received Multiply({0},{1})", n1, n2);
  80.                 Console.WriteLine("Return: {0}", result);
  81.                 return result;
  82.             }
  83.  
  84.             public double Divide(double n1, double n2)
  85.             {
  86.                 double result = n1 / n2;
  87.                 Console.WriteLine("Received Divide({0},{1})", n1, n2);
  88.                 Console.WriteLine("Return: {0}", result);
  89.                 return result;
  90.             }
  91.         }
  92.     }
  93. }
  94.        
  95. Uri BaseAddress = new Uri("http://locoalhost:8000/ServiceModelSamples/Service");