How to: Implement a Windows Communication Foundation Service Contract

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.

时间: 2024-11-03 05:29:07

How to: Implement a Windows Communication Foundation Service Contract的相关文章

How to: Define a Windows Communication Foundation Service Contract

This is the first of six tasks required to create a basic Windows Communication Foundation (WCF) application. For an overview of all six of the tasks, see the Getting Started Tutorial topic. 创建一个wcf应用需要6个步骤,本篇文章涉及的是第一个步骤. When creating a WCF service,

How to: Host and Run a Basic Windows Communication Foundation Service

This is the third of six tasks required to create a Windows Communication Foundation (WCF) application. For an overview of all six of the tasks, see the Getting Started Tutorial topic. This topic describes how to host a Windows Communication Foundati

概览 Windows Communication Foundation (WCF) 体系结构及其主要概念。代码示例演示 WCF 约定、终结点和行为

摘要:概览 Windows Communication Foundation (WCF) 体系结构及其主要概念.代码示例演示 WCF 约定.终结点和行为. 本页内容 简介 WCF 基础 代码示例 小结 简介 本文档提供 Windows Communication Foundation (WCF) 体系结构的概览.本文旨在阐释 WCF 中的主要概念以及它们如何协调工作.还有几个代码示例对这些概念进行深入阐释,但代码不是本文档的重点. 本文档下面的部分分为以下两个主要内容: WCF 基础:涵盖 WC

.NET Framework 4.6 and 4.5 > 开发指南 > 使用 WCF 的面向服务的应用程序 > Windows Communication Foundation (WCF)

.NET Framework 4.6 and 4.5 > 开发指南 >  使用 WCF 的面向服务的应用程序 > Windows Communication Foundation (WCF) :https://msdn.microsoft.com/zh-cn/library/dd456779(v=vs.110).aspx 文档指南: https://msdn.microsoft.com/zh-cn/library/ms730846(v=vs.110).aspx 入门教程: https:/

MSDN 提供的有关 Windows Communication Foundation (WCF) 的各个方面的示例说明

有关 Windows Communication Foundation (WCF) 的各个方面的示例说明: https://www.microsoft.com/en-us/download/details.aspx?id=21459 或者:http://files.cnblogs.com/files/djdq/WF_WCF_Samples.part01.rar 和 http://files.cnblogs.com/files/djdq/WF_WCF_Samples.part02.rar 或者:(

Windows Communication Foundation (WCF)和Windows CardSpace的示例程序

微软公司昨天发布了一个Windows Communication Foundation (WCF)和Windows CardSpace的示例程序包,内容极为丰富,从最简单的Hello World到复杂的解决方案一应俱全.对于Windows Communication Foundation (WCF)和Windows CardSpace这两个新东西而言,这些示例程序无疑就是最好的学习资源. 下载地址:http://www.microsoft.com/downloads/details.aspx?F

Windows Communication Foundation(WCF)服务项目分类7756fgf

baozoumanhua.com/users/17321075/forum_articlesbaozoumanhua.com/users/17321075/followingsbaozoumanhua.com/users/17321075/talkingsbaozoumanhua.com/users/17321075/following_articlesbaozoumanhua.com/users/17321075/articlesbaozoumanhua.com/users/17321105b

Windows Workflow Foundation技术介绍(基于.NET Framework 4.5)

Windows Workflow Foundation技术介绍(基于.NET Framework 4.5) 转自:http://www.cpiso.cn/jsyj/ghxx/2014/5/15/459.shtml Microsoft Windows Workflow Foundation (WF) 是一个可扩展框架,用于在 Windows 平台上开发工作流解决方案.Windows Workflow Foundation 同时提供了 API 和一些工具,用于开发和执行基于工作流的应用程序.Wind

为应用程序池“XX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误

场景 WCF应用程序部署在IIS7中,使用net.tcp协议对外给几百台客户端提供服务,应用程序池不断崩溃重启. 分析过程 在事件查看器中看到的错误信息类似于 为应用程序池"XX"提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误 使用windbg在崩溃时进行分析,找到引发崩溃的堆栈的最顶部信息进行搜索,找到两个补丁包安装上 用于搜索的顶部异常信息为:IOCompletionThunk.UnhandledExceptionFra