static void Main(string[] args) { var cfV2 = new ChannelFactory<IComplexNumber>("secondVersionEndUsers"); var channelV2 = cfV2.CreateChannel(); var z1 = new ComplexNumber(); var z2 = new ComplexNumber(); z1.Real = 1D; z1.Imaginary = 2D; z2.Real = 2D; z2.Imaginary = 1D; Console.WriteLine("*** Service Versioning: end-users of the second version ***\n"); Console.WriteLine("\nPlease hit any key to run OR enter 'exit' to terminate."); string command = Console.ReadLine(); while (command != "exit") { Console.WriteLine("Please hit any key to simulate secondVersionEndUsers: "); Console.ReadLine(); using (new OperationContextScope((IContextChannel)channelV2)) { OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Version", "http://custom/namespace", "v2.0")); ComplexNumberArithmetics(channelV2, z1, z2); } Console.WriteLine("\nPlease hit any key to re-run OR enter 'exit' to terminate."); command = Console.ReadLine(); } ((IClientChannel)channelV2).Close(); }
public double Argument(ComplexNumber x) { Console.WriteLine("Invoked ARGUMENT operation."); var argumentX = Math.Atan(x.Imaginary / x.Real); return argumentX; }
public double Modulus(ComplexNumber x) { Console.WriteLine("Invoked MODULUS operation."); var modX = Math.Sqrt(x.Real * x.Real + x.Imaginary * x.Imaginary); return modX; }
public ComplexNumber Conjugate(ComplexNumber x) { Console.WriteLine("Invoked CONJUGATE Operation."); var z = new ComplexNumber(); z.Real = x.Real; z.Imaginary = -1 * x.Imaginary; return z; }
public ComplexNumber Add(ComplexNumber x, ComplexNumber y) { Console.WriteLine("Invoked ADD operation."); var z = new ComplexNumber(); z.Real = x.Real + y.Real; z.Imaginary = x.Imaginary + y.Imaginary; return z; }
public ComplexNumber Multiply(ComplexNumber x, ComplexNumber y) { Console.WriteLine("Invoked MULTIPLY Operation."); var z = new ComplexNumber(); z.Real = x.Real * y.Real - x.Imaginary * y.Imaginary; z.Imaginary = x.Real * y.Imaginary + x.Imaginary * y.Real; return z; }
public ComplexNumber Subtract(ComplexNumber x, ComplexNumber y) { Console.WriteLine("Invoked SUBTRACT operation."); var z = new ComplexNumber(); z.Real = x.Real - y.Real; z.Imaginary = x.Imaginary - y.Imaginary; return z; }
public ComplexNumber Divide(ComplexNumber x, ComplexNumber y) { Console.WriteLine("Invoked DIVIDE Operation."); var z = new ComplexNumber(); var modulusY = Math.Sqrt(y.Real * y.Real + y.Imaginary * y.Imaginary); z.Real = (x.Real * y.Real + x.Imaginary * y.Imaginary) / (modulusY * modulusY); z.Imaginary = (x.Imaginary * y.Real - x.Real * y.Imaginary) / (modulusY * modulusY); return z; }
static void ComplexNumberArithmetics(IComplexNumber channel, ComplexNumber z1, ComplexNumber z2) { try { Console.WriteLine("{0} + {1} = {2}", f(z1), f(z2), f(channel.Add(z1, z2))); Console.WriteLine("{0} - {1} = {2}", f(z1), f(z2), f(channel.Subtract(z1, z2))); Console.WriteLine("{0} * {1} = {2}", f(z1), f(z2), f(channel.Multiply(z1, z2))); Console.WriteLine("{0} / {1} = {2}", f(z1), f(z2), f(channel.Divide(z1, z2))); Console.WriteLine("Conjugate[{0}] = {1}", f(z1), f(channel.Conjugate(z1))); Console.WriteLine("Reciprocal[{0}] = {1}", f(z1), f(channel.Reciprocal(z1))); Console.WriteLine("Modulus[{0}] = {1}", f(z1), channel.Modulus(z1)); Console.WriteLine("Argument[{0}] = {1} Radians", f(z1), channel.Argument(z1)); } catch (Exception fx) { Console.WriteLine(fx.Message); } }
static string f(ComplexNumber z) { return (String.Format("({0}, {1})", z.Real, z.Imaginary)); }
public ComplexNumber Reciprocal(ComplexNumber x) { Console.WriteLine("Invoked RECIPROCAL operation."); var z = new ComplexNumber(); var conjugateX = new ComplexNumber(); var modulusX = Math.Sqrt(x.Real * x.Real + x.Imaginary * x.Imaginary); conjugateX.Real = x.Real; conjugateX.Imaginary = -1 * x.Imaginary; z.Real = conjugateX.Real / (modulusX * modulusX); z.Imaginary = conjugateX.Imaginary / (modulusX * modulusX); return z; }