• Step2


    This is the second of six tasks required to create a basic Windows Communication Foundation (WCF) service and a client that can call the service. For an overview of all six tasks, see the Getting Started Tutorial topic.

    The next step in creating a WCF application is to implement the service interface. This involves creating a class called CalculatorService that implements the user-defined ICalculator interface..

    To implement a WCF service contract

    • Open the Service1.cs or Service1.vb file and add the following code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace GettingStartedLib
    {
    
        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;
            }
        }
    }

    Each method implements the calculator operation and writes some text to the console to make testing easier.

  • 相关阅读:
    php面向对象方法
    php数组中元素的操作
    PHP数组的排序
    [设计模式]抽象工厂模式
    [设计模式]建造者模式
    [设计模式]工厂方法模式
    [设计模式]简单工厂模式
    [设计模式]单例模式
    设计模式系列
    JAVA 设计模式 状态模式
  • 原文地址:https://www.cnblogs.com/chucklu/p/4631086.html
Copyright © 2020-2023  润新知