Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Trouble following Microsoft's WCF tutorial
- svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceModel;
- using System.ServiceModel.Description;
- namespace Microsoft.ServiceModel.Samples
- {
- class Program
- {
- static void Main(string[] args)
- {
- Uri BaseAddress = new Uri("http://locoalhost:8000/ServiceModelSamples/Service");
- ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), BaseAddress);
- try
- {
- selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");
- ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
- smb.HttpGetEnabled = true;
- selfHost.Description.Behaviors.Add(smb);
- selfHost.Open();
- Console.WriteLine("The service is ready.");
- Console.WriteLine("Press <ENTER> to terminate service.");
- Console.WriteLine();
- Console.ReadLine();
- selfHost.Close();
- }
- catch (CommunicationException ce)
- {
- Console.WriteLine("An expection occurred: {0}", ce.Message);
- selfHost.Abort();
- }
- }
- [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
- public interface ICalculator
- {
- [OperationContract]
- double Add(double n1, double n2);
- [OperationContract]
- double Subtract(double n1, double n2);
- [OperationContract]
- double Multiply(double n1, double n2);
- [OperationContract]
- double Divide(double n1, double n2);
- }
- public class CalculatorService : ICalculator
- {
- public double Add(double n1, double n2)
- {
- double result = n1 + n2;
- Console.WriteLine("Received Add({0},{1})", n1, n2);
- // Code added to write output to the console window.
- Console.WriteLine("Return: {0}", result);
- return result;
- }
- public double Subtract(double n1, double n2)
- {
- double result = n1 - n2;
- Console.WriteLine("Received Subtract({0},{1})", n1, n2);
- Console.WriteLine("Return: {0}", result);
- return result;
- }
- public double Multiply(double n1, double n2)
- {
- double result = n1 * n2;
- Console.WriteLine("Received Multiply({0},{1})", n1, n2);
- Console.WriteLine("Return: {0}", result);
- return result;
- }
- public double Divide(double n1, double n2)
- {
- double result = n1 / n2;
- Console.WriteLine("Received Divide({0},{1})", n1, n2);
- Console.WriteLine("Return: {0}", result);
- return result;
- }
- }
- }
- }
- Uri BaseAddress = new Uri("http://locoalhost:8000/ServiceModelSamples/Service");
Advertisement
Add Comment
Please, Sign In to add comment