http://www.tutorialspoint.com/wcf/wcf_creating_service.htm

Creating a WCF service is a simple task using Microsoft Visual Studio 2012. Given below is the step-by-step method for creating a WCF service along with all the requisite coding, to understand the concept in a better way.

在VS2012中创建一个wcf服务是一个简单的任务。为了更好的理解之前的概念,按照下面的方法,一步一步的创建一个wcf服务,同时也包含了所有必须的编码

  • Launch Visual Studio 2012.   首先启动vs2012
  • Click on new project, then in Visual C# tab, select WCF option.   新建项目,然后选择模板-->C#-->WCF  右侧选择wcf库

A WCF service is created that performs basic arithmetic operations like addition, subtraction, multiplication, and division. The main code is in two different files – one interface and one class.

A WCF contains one or more interfaces and its implemented classes.

我们创建一个执行基础算数运算的wcf服务:实现加减乘除。主要的代码在2个不同的文件中,一个接口另外是类

wcf包含至少一个接口以及实现了接口的类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to
// change the interface name "IService1" in both code and config file
// together.
[ServiceContract]
public interface IService1
{
[OperationContract]
int Sum(int numer1, int number2); [OperationContract]
int Substract(int number1, int number2); [OperationContract]
int Multiply(int number1, int number2); [OperationContract]
int Divide(int number1, int number2);
} // Use a data contract as illustrated in the sample below to add
// composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello "; [DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
} [DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}

The code behind its class is given below.  实现了接口的类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to
// change the class name "Service1" in both code and config file
// together.
public class Service1 : IService1
{
/// <summary>
/// This Function Returns summation of two integer numbers
/// </summary>
/// <param name="number1"></param>
/// <param name="number2"></param>
/// <returns></returns>
public int Sum(int number1, int number2)
{
return number1 + number2;
} /// <summary>
/// This function returns subtraction of two numbers.
/// If number1 is smaller than number2 then this function returns 0
/// </summary>
/// <param name="number1"></param>
/// <param name="number2"></param>
/// <returns></returns>
public int Substract(int number1, int number2)
{
if (number1 > number2)
{
return number1 - number2;
}
else
{
return ;
}
} /// <summary>
/// This function returns multiplication of two integer numbers.
/// </summary>
/// <param name="number1"></param>
/// <param name="number2"></param>
/// <returns></returns>
public int Multiply(int number1, int number2)
{
return number1 * number2;
} /// <summary>
/// This function returns integer value of two integer number.
/// If num2 is 0 then this function returns 1
/// </summary>
/// <param name="number1"></param>
/// <param name="number2"></param>
/// <returns></returns>
public int Divide(int number1,int number2)
{
if (number2 != )
{
return number1 / number2;
}
else
{
return ;
}
}
}
}

To run this service, click the Start button in Visual Studio.

While we run this service, the following screen appears.

服务运行起来之后,会出现以下的界面。  双击某一个函数来执行相应的操作

On clicking the sum method, the following page opens. Here, you can enter any two integer numbers and click on the Invoke button. The service will return the summation of those two numbers.

双击了Sum方法后,会出现下面的页面。可以输入number和number2的值,然后点击调用。然后服务会返回2个数字的和。

Like summation, we can perform all other arithmetic operations which are listed in the menu. And here are the snaps for them.

The following page appears on clicking the Subtract method. Enter the integer numbers, click the Invoke button, and get the output as shown here:

The following page appears on clicking the Multiply method. Enter the integer numbers, click the Invoke button, and get the output as shown here:

The following page appears on clicking the Divide method. Enter the integer numbers, click the Invoke button, and get the output as shown here:

Once the service is called, you can switch between them directly from here.

一旦某一个方法的服务被调用后,可以直接通过tab和切换它们,也可以重新打开一个新的

WCF - Creating WCF Service的更多相关文章

  1. wcf和web service的区别

    1.WebService:严格来说是行业标准,不是技术,使用XML扩展标记语言来表示数据(这个是夸语言和平台的关键).微软的Web服务实现称为ASP.NET Web Service.它使用Soap简单 ...

  2. WCF和Web Service的 区(guan)别(xi)

    参考文献:http://social.microsoft.com/Forums/zh-CN/c06420d1-69ba-4aa6-abe5-242e3213b68f/wcf-webservice 之前 ...

  3. WCF与 Web Service的区别是什么?各自的优点在哪里呢?

    这是很多.NET开发人员容易搞错的问题.面试的时候也经常遇到,初学者也很难分快速弄明白 Web service: .net技术中其实就指ASP.NET Web Service,用的时间比较长,微软其实 ...

  4. 跟我一起学WCF(13)——WCF系列总结

    引言 WCF是微软为了实现SOA的框架,它是对微乳之前多种分布式技术的继承和扩展,这些技术包括Enterprise Service..NET Remoting.XML Web Service.MSMQ ...

  5. Learing WCF Chapter1 WCF Services

    WCF ServicesWCF services are the new distributed boundary in an enterprise application—with an empha ...

  6. WCF - Consuming WCF Service

    WCF services allow other applications to access or consume them. A WCF service can be consumed by ma ...

  7. WCF - Hosting WCF Service

    After creating a WCF service, the next step is to host it so that the client applications can consum ...

  8. WCF - Hosting WCF Service 四种托管方式

    https://www.tutorialspoint.com/wcf/wcf_hosting_service.htm After creating a WCF service, the next st ...

  9. 使用WCF 创建 Rest service

    REST SERVICE 允许客户端修改url路径,并且web端功过url 请求数据. 他使用http协议进行通讯,想必大家都知道 . 并且我们可以通过设置进行数据类型转换, 支持XML,JSON 格 ...

随机推荐

  1. iOS中 常用的mac终端指令

    1.使用caffeinate阻止Mac运行屏幕保护和睡眠 caffeinate能阻止Mac进入睡眠状态,而且屏幕保护也不会激活.我们最好使用-t为命令加入具体的时间.比如下面的命令可以使Mac一小时内 ...

  2. bzoj4637:期望

    思路:最小生成树计数只不过加了一个期望,由于期望具有线性性质,就可以转化为每条边的期望之和,那么一条边的期望如何求呢,在最小生成树记数中,是把相同边权的一起处理,之后把属于连通块内的点缩点,也就是说, ...

  3. sgu 109 Magic of David Copperfield II

    这个题意一开始没弄明白,后来看的题解才知道这道题是怎么回事,这道题要是自己想难度很大…… 你一开始位于(1,1)这个点,你可以走k步,n <= k < 300,由于你是随机的走的, 所以你 ...

  4. OpenJudge 2739 计算对数

    1.链接地址: http://bailian.openjudge.cn/practice/2739/ 2.题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 给定两个正整数a和b.可 ...

  5. plsql通过instantclient连接oracle数据库报连接超时

    配置:数据库oracle10.2;服务器操作系统centos5.5:客户机操作系统win7 32位:plsql版本10.0.5 配置前提必须关闭客户机与服务器操作系统的防火墙,否则会出现“连接超时”的 ...

  6. 开发APP不搞清楚这20个问题,必然沦为一场灾难

    移动经济的高速增长极大刺激了企业和个人的APP开发热情,从卖野山鸡的到卖无人机的,从老大妈到小正太都跃跃欲试,更不要说那些传统企业的信息主管们了. 面对今天如过江之鲫的APP市场,很少有人意识到,移动 ...

  7. Css3 阴影效果

    box-shadow:#333 0 0 5px 10px; //上下左右有阴影-webkit-box-shadow: #666 0px 5px 10px; -moz-box-shadow: #666 ...

  8. 【3】Bootstrap的下载和目录结构

    [1]下载 去中方官网下载http://www.bootcss.com/ 如果你是做网页练习,你可以使用CDN加速服务,免去下载等痛苦,当然你使用的时候必须有连接上网络.中方的官网也提供了很多种类的C ...

  9. Popen No such file or directory 错误

    File , in reload_config stderr=PIPE, env={"PATH": '', "HOME": "/root"} ...

  10. STM32之触摸屏

    一.触摸屏控制器简介 1.TSC2046概貌 2.TSC2046引脚描述 3.TSC2046应用电路 4.常见接线方法 YU=Y- YD=Y+ XL=X- XR=X+ 二.TSC2046编程注意事项 ...