zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    PAT (Advanced Level) 1017. Queueing at Bank (25)
    PAT (Advanced Level) 1016. Phone Bills (25)
    1sting
    八皇后问题
    思维水题
    pigofzhou的巧克力棒
    喵哈哈村的代码传说 第四章 并查集
    简单容器应用
    Codefroces D2. Magic Powder
    喵哈哈村的种花魔法(线段树(区间更新,单点查询),前缀和(单点更新,区间查询))
  • 原文地址:https://www.cnblogs.com/chucklu/p/4631086.html
Copyright © 2011-2022 走看看