WCF - Creating WCF Service
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的更多相关文章
- wcf和web service的区别
1.WebService:严格来说是行业标准,不是技术,使用XML扩展标记语言来表示数据(这个是夸语言和平台的关键).微软的Web服务实现称为ASP.NET Web Service.它使用Soap简单 ...
- WCF和Web Service的 区(guan)别(xi)
参考文献:http://social.microsoft.com/Forums/zh-CN/c06420d1-69ba-4aa6-abe5-242e3213b68f/wcf-webservice 之前 ...
- WCF与 Web Service的区别是什么?各自的优点在哪里呢?
这是很多.NET开发人员容易搞错的问题.面试的时候也经常遇到,初学者也很难分快速弄明白 Web service: .net技术中其实就指ASP.NET Web Service,用的时间比较长,微软其实 ...
- 跟我一起学WCF(13)——WCF系列总结
引言 WCF是微软为了实现SOA的框架,它是对微乳之前多种分布式技术的继承和扩展,这些技术包括Enterprise Service..NET Remoting.XML Web Service.MSMQ ...
- Learing WCF Chapter1 WCF Services
WCF ServicesWCF services are the new distributed boundary in an enterprise application—with an empha ...
- WCF - Consuming WCF Service
WCF services allow other applications to access or consume them. A WCF service can be consumed by ma ...
- WCF - Hosting WCF Service
After creating a WCF service, the next step is to host it so that the client applications can consum ...
- WCF - Hosting WCF Service 四种托管方式
https://www.tutorialspoint.com/wcf/wcf_hosting_service.htm After creating a WCF service, the next st ...
- 使用WCF 创建 Rest service
REST SERVICE 允许客户端修改url路径,并且web端功过url 请求数据. 他使用http协议进行通讯,想必大家都知道 . 并且我们可以通过设置进行数据类型转换, 支持XML,JSON 格 ...
随机推荐
- ASP.NET Web Service如何工作(2)
ASP.NET Web Service如何工作(2) [日期:2003-06-26] 来源:CSDN 作者:sunnyzhao(翻译) [字体:大 中 小] HTTP管道一旦调用了.asmx句柄,便 ...
- NSArray函数
1.判断是否包含某一个元素,返回1则表示有 - (BOOL)countainsObject:(id)anObject BOOL isContain = [arrayboy containsObject ...
- QT 常用设置
博文都写在了云笔记里面了,见谅,不想维护两个版本. QT 常用设置
- .net Remoting 的工作原理是什么?
webservice和.net remoting都是用来通信的框架,它们最大的优点是可以像调用本地对象一样调用远程对象 区别:1.webservice是用的应用层协议http封装的,所以它可以被很多其 ...
- 关于WPF中Popup控件的小记
在wpf开发中,常需要在鼠标位置处弹出一个“提示框”(在此就以“提示框”代替吧),通过“提示框”进行信息提示或者数据操作,如果仅仅是提示作用,使用ToolTip控件已经足够,但是有些是需要在弹出的框中 ...
- MVC , MVP , MVVM【转 阮一峰的网络日志】
一.MVC MVC模式的意思是,软件可以分成三个部分. 视图(View):用户界面. 控制器(Controller):业务逻辑 模型(Model):数据保存 各部分之间的通信方式如下. View 传送 ...
- rhel_6.x 安装mysql
不知为何mysql的官网很难下载,本人网上找了好久,终于找到了个镜像: 特别感谢http://mirrors.sohu.com/mysql/MySQL-5.6/ ^_^ 首先下载mysql的下面 ...
- ECshop网店系统百万级商品量性能优化-加快首页访问速度
如果ECshop的商品数达到几万,十几万的时候,如果首页没有缓存,第一次访问的时候,你会发现其慢无比,原因就是清空了Cache后或者没有Cache的情况下,ECshop会Bulid一些Cache数据, ...
- c#画正弦波
/// <summary> /// 画正弦曲线 /// </summary> /// <param name="sender"></par ...
- Authentication for the REST APIs
HTTP基本认证原理 在HTTP协议进行通信的过程中,HTTP协议定义了基本认证过程以允许HTTP服务器对WEB浏览器进行用户身份认证的方法,当一个客户端向HTTP服务器进行数据请求时,如果客户端未被 ...